How do I get the default_provider field to only list providers that belong to 
this Partner?


class Partner(Model):
    id = UUIDField(primary_key=True)
    ...
    default_provider = ForeignKey('Provider', null=True, blank=True)
    providers = ManyToManyField('Provider', related_name='provider_partners', 
blank=True, null=True)


class PartnerAdmin(ModelAdmin):
    list_display = ('name', 'type', 'url')
    list_filter = ('type',)
    exclude = ['calls','providers' ]
    raw_id_fields = ('admins',)
    
    inlines = [ PartnerRegistrationInline, ]
    
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if db_field.name == "default_provider":
            kwargs["queryset"] = self.model.providers.all()
            return db_field.formfield(**kwargs)
        return super(PartnerAdmin, self).formfield_for_foreignkey(db_field, 
request, **kwargs)



The code above generates an AttributeError:

'ReverseManyRelatedObjectsDescriptor' object has no attribute 'all'

--
Eric Chamberlain






--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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