Hey Rob,
You can override save_formset() method of ModelAdmin for this. Create
a method update_total_amount(self) in your Ticket Model.
class TicketAdmin(admin.ModelAdmin):
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
instance.user = request.user
instance.save()
formset.save_m2m()
## call update_total_amount()
instance.update_total_amount()
Useful Links -
1. https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_formset
2. https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_formset
Sincerely,
Pankaj Singh
http://about.me/psjinx
On Sat, Feb 2, 2013 at 8:29 PM, Rob <rob@wieskamp.nl> wrote:
> I have two models:
>
> class Tickets(models.Model):
> ticketnumber = models.IntegerField()
> total_amount = models.DecimalField()
>
> class TicketItems(models.Model):
> name = models.Charfield(max_length=30)
> ticket = models.ForeignKey(Tickets)
> price = models.DecimalField()
> amount = models.IntergerField()
>
> I have an inline Adminpage were users can add TicketItems. How do I update
> the total_amount of model Tickets from all TicketItems on save (price *
> amount)?
>
> Django 1.4
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment