<commit_before>from tastypie.resources import ModelResource, ALL
from tastypie import fields

from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist

from datapoints.api.base import BaseApiResource
from datapoints.models import *



class OfficeResource(BaseApiResource):
    '''Office Resource'''


    class Meta(BaseApiResource.Meta):
        queryset = Office.objects.all()
        resource_name = 'office'



class RegionResource(BaseApiResource):
    '''Region Resource'''

    parent_region = fields.ForeignKey('datapoints.api.simple.RegionResource', 'parent_region', full=False, null=True)
    office = fields.ToOneField(OfficeResource, 'office')


    class Meta(BaseApiResource.Meta):
        queryset = Region.objects.all()
        resource_name = 'region'
        filtering = {
            "slug": ('exact'),
            "id": ALL,
            "office": ALL,
            "region_type": ALL,
        }

    def dehydrate(self, bundle):

        bundle.data['office'] = bundle.obj.office.id

        try:
            bundle.data['parent_region'] = bundle.obj.parent_region.id
        except ObjectDoesNotExist:
            pass<commit_msg>fix invalid reference to region resource<commit_after>from tastypie.resources import ModelResource, ALL
from tastypie import fields

from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist

from datapoints.api.base import BaseApiResource
from datapoints.models import *



class OfficeResource(BaseApiResource):
    '''Office Resource'''


    class Meta(BaseApiResource.Meta):
        queryset = Office.objects.all()
        resource_name = 'office'



class RegionResource(BaseApiResource):
    '''Region Resource'''

    parent_region = fields.ForeignKey('datapoints.api.meta_data.RegionResource', 'parent_region', full=False, null=True)
    office = fields.ToOneField(OfficeResource, 'office')


    class Meta(BaseApiResource.Meta):
        queryset = Region.objects.all()
        resource_name = 'region'
        filtering = {
            "slug": ('exact'),
            "id": ALL,
            "office": ALL,
            "region_type": ALL,
        }

    def dehydrate(self, bundle):

        bundle.data['office'] = bundle.obj.office.id

        try:
            bundle.data['parent_region'] = bundle.obj.parent_region.id
        except ObjectDoesNotExist:
            pass
{'fraction_non_alphanumeric': 0.1043910521955261, 'fraction_numerical': 0.0, 'mean_word_length': 2.998344370860927, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2731664', 'n_tokens_mistral': 702, 'n_tokens_neox': 661, 'n_words': 148}