You could do this with some javascript, which might work better in the
following scenario:

If you change the state of Completed between True and False, then
other options will be enabled/disabled for you by the javascript

My "take" on the admin screens is its a facility to fiddle with the
model, and less a "workflow" oriented system. For "workflow" you would
likely create your own views/templates/etc.

So, even if you say "a stockorder can never be switched from completed
to uncompleted", there are times you may require adjustments because
something went awry. This is exactly what the admin screens are for:
the admin fixing the data.

If you want to prevent your users from doing that operation (completed
to uncompleted), then write views that prevent this.

If you determine that the model does not allow that transition, then
you can do that enforcement inside the model (the clean() method in
version 1.2), so if you were to make that "tweak" in the admin screen,
it will refuse to save.



On Feb 28, 5:00 am, 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.

Reply via email to