On Feb 28, 12:21 pm, Simon Davies <simon...@gmail.com> wrote: > figured out how to do it using the get_form method like this: > > class AccessoryStockOrderAdmin(admin.ModelAdmin): > form = AccessoryStockOrderForm > def get_form(self, request, obj=None, **kwargs): > form = super(AccessoryStockOrderAdmin, self).get_form(request, > obj, **kwargs) > if obj == None: > del form.base_fields['cancelled'] > return form >
If it is just the add_view you want to change another way is to modify the add_view method: def add_view (self, *args, **kwargs): self.exclude = ('primary_phone','primary_email','primary_address') return super(ContactAdmin, self).add_view(*args, **kwargs) But I found doing this I needed to explicitly reset exclude to None for other views - as it was being remembered somewhere. -Preston > On 28 Feb, 13:00, Simon Davies <simon...@gmail.com> wrote: > > > > > Hi > > > I have a model which I access from the admin application. I want to > > exclude some fields dynamically. > > > My model looks like this: > > > class StockOrder(models.Model): > > number_of_items_pending_order = > > models.PositiveIntegerField(max_length=5, default=1) > > number_of_items_ordered = models.PositiveIntegerField(max_length=5, > > default=1) > > number_of_items_delivered = > > models.PositiveIntegerField(max_length=5, > > default=1) > > order_date = models.DateTimeField(auto_now_add=True, > > verbose_name=u'Date ordered') > > confirmed = models.BooleanField(default=False) > > confirmed_date = models.DateTimeField(verbose_name=u'Date > > confirmed', > > null=True, blank=True) > > cancelled = models.BooleanField(default=False) > > cancel_date = models.DateTimeField(verbose_name=u'Date cancelled', > > null=True, blank=True) > > completed = models.BooleanField(default=False) > > completion_date = models.DateTimeField(verbose_name=u'Date > > completion', null=True, blank=True) > > > I want to exclude some fields depending on the state of others. So if > > completed is True I don't want to see the confirmed or cancelled > > flags. > > > The options to exclude fields I understand are: > > > 1: ModelAdmin.exclude attribute in admin.py. I can't see how this > > can be manipulated dynamically however. > > > 2. I create my own Modelform and set the form attribute in admin.py > > to the modelform, the modelform will look something like this: > > > class StockOrderForm(ModelForm): > > class Meta: > > model = StockOrder > > exclude = ('cancelled',) > > > However I run into the same problem as in 1, how can I manipulate the > > exclude parameter. Is it possible to do so in __init__? > > > Thanks > > > Simon -- 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.