Django Model Inheritance and limit_choices_to


Django Model Inheritance and limit_choices_to



Can anyone tell me how i can limit the choices for the Page model which i inherit from in the following code?

class CaseStudy(Page):     """      An entry in a fancy picture flow widget for a case study page     """     image = models.ForeignKey(Image, limit_choices_to={'is_active': True, 'category__code':'RP'})      def __unicode__(self):         return u"%s" % self.title 

The django admin is limiting the image choices in a drop down successfully, but i would like to limit a field in the Page model as well (a 'parent page field'), ie:

class Page(models.Model):     parent              = models.ForeignKey('self', blank=True, null=True, related_name='children') 



Manipulating Data in Django's Admin Panel on Save

1:



Django: Structure Django Model to allow Arbitrary Fieldtypes
I managed to work this out - by overriding the admin model form.


Admin, two links to different views?
I realise this could be tightened up, but thought it might come in use to someone out there.


Django find in joined set
Here's an excerpt from the admin.py .
Django: Why are my forms' textfields and imagefields never instantiated but all other fields instantiate ok?
class CaseStudyForm(forms.ModelForm):     def __init__(self, *args, **kwargs):         super(CaseStudyForm, self).__init__(*args, **kwargs)          recent_project_page = Page.objects.get(title="Recent Projects")                 parent_widget = self.fields['parent'].widget         choices = []         for key, value in parent_widget.choices:             if key in [recent_project_page.id,]:                 choices.append((key, value))         parent_widget.choices = choices   class CaseStudyAdmin(admin.ModelAdmin):     form = CaseStudyForm  admin.site.register(CaseStudy, CaseStudyAdmin) 


Django re-orden form fields?


88 out of 100 based on 88 user ratings 538 reviews