On Feb 9, 7:28 pm, phoebebright <phoebebright...@gmail.com> wrote:
> I have implemented this solution successfully with a standard model,
> but when I try to use it on one which is subclassed I get an error
> because it is trying to validate the model before it knows about the
> subclass.  I can work around this by defining an Admin class for each
> of the subclasses, but it seems to me this should work?
>
> Model.py
>
> class Directory(models.Model):
>     name = models.CharField(max_length=60)
>     pic1 = models.ImageField(upload_to='pics', blank=True,
> null=True)
>
> class Business(Directory):
>     cat = models.ForeignKey(Subcategory)
>
> Admin.py
>
> AdminImageWidget defined ....
>
> class DirectoryAdminForm(forms.ModelForm):
>     pic1 = forms.ImageField(widget=AdminImageWidget())
>
>     class Meta:
>         model = Directory
>
> class DirectoryAdmin(admin.ModelAdmin):
>
>     form = DirectoryAdminForm
>
>     fieldsets = [
>         (None,   {'fields': ['cat','name','is_live']}),    <--------
> CAT FIELD IS PART OF BUSINESS NOT DIRECTORY SO CAUSES ERROR
>         ('Contact', {'fields':
> ['phone','mobile','fax','email','web','address']}),
>         ('Details', {'fields':
> ['description','pic1','pic2','pic3','pic4']}),
>     ]
>
> admin.site.register(Business,DirectoryAdmin)
>
> Error
>
> ImproperlyConfigured at /admin/town/business/14/
>
> 'DirectoryAdmin.fieldsets[2][1]['fields']' refers to field 'cat' that
> is missing from the form.

The error message tells you what is going on. Your form definition has
model=Directory in its Meta class, so it only contains fields from the
Directory model. If you want it to contain the fields from the
subclassed Business model, you'll need to change that Meta
declaration.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to