Tuesday, June 29, 2010

Re: Django admin - Edit parent model and related models on the same page

On Jun 28, 1:48 am, DoubleD <ddemide...@gmail.com> wrote:
> I want to be able to edit all data on one page. How can i achieve
> this ? Should i modify my models? If so, then how should i modify
> them?
>
> class TextStyle(models.Model):
>     color = models.CharField(_("color"), max_length=7)
>     style = models.CharField(_("style"), max_length=30)
>     typeface = models.CharField(_("typeface"), max_length=100)
>
> class GenericText(models.Model):
>     text = models.TextField(_("text"))
>     lines = models.IntegerField(_("number of lines"))
>     style = models.ForeignKey(TextStyle, verbose_name=_('text style'),
> blank=False)
>
> class ExpirationDate(models.Model):
>     date = models.DateField(_("date"))
>     style = models.ForeignKey(TextStyle, verbose_name=_('text style'),
> blank=False)
>
> class Coupon(models.Model):
>     name = models.CharField(_("name"), max_length=100)
>     slug = AutoSlugField(populate_from="title")
>     background = models.ImageField(upload_to="userbackgrounds")
>     layout = models.ForeignKey(Layout, verbose_name=("layout"),
> blank=False)
>     logo = models.ImageField(upload_to="logos")
>     title = models.OneToOneField(GenericText, verbose_name=("title"),
> blank=False, related_name="coupon_by_title")
>     body = models.OneToOneField(GenericText, verbose_name=("body"),
> blank=False, related_name="coupon_by_body")
>     disclaimer = models.OneToOneField(GenericText,
> verbose_name=("disclaimer"), blank=False,
> related_name="coupon_by_disclaimer")
>     promo_code = models.OneToOneField(GenericText,
> verbose_name=("promo code"), blank=False,
> related_name="coupon_by_promo")
>     bar_code = models.OneToOneField(BarCode, verbose_name=("barcode"),
> blank=False, related_name="coupon_by_barcode")
>     expiration = models.OneToOneField(ExpirationDate,
> verbose_name=("expiration date"), blank=False,
> related_name="coupon_by_expiration")
>     is_template = models.BooleanField( verbose_name=("is a
> template"), )
>     category = models.ForeignKey(Category, verbose_name=("category"),
> blank=True,null=True, related_name="coupons")
>     user = models.ForeignKey(User, verbose_name=("user"), blank=False)

Its not entirely clear what you want to achieve... have you looked at
using inline model editing?
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment