I have this code
class DistrictResource(ModelResource):
model=models.District
res_name="district"
class Meta:
queryset = self.model.District.objects.active()
how can i use self.model in meta as i get error if i use self
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to use
instead of
in this case.
Edit:
You cannot access
res_nameinside the inner class because of the rule of scope resolution in Python:An easy rule to remember about Python Scope resolution is the LEGB rule:
L. Locals, i.e., names assigned within a function.
E. Enclosing function locals.
G. Globals
B. Built-ins.
class Metais used by Django/Tastypie as configuration options when they use metaclass to construct the class. I am not sure why you would want to access a variable outsideMetafrom withinMeta, rather than just define it insideMeta.