[Answered ]-Being able to have multiple items in Django

1👍

Yeah, the tutorial says ‘Also note the “Add Another” link next to “Poll.” Every object with a ForeignKey relationship to another gets this for free.’.

And personally, I would add a foreign key to user. Which the solution here says to do by:

from django.contrib.auth.models import User
...
user = models.ForeignKey(User)

That way, you know which products belong to which users.

1👍

You need to add a ForeginKey relationship between your ProductOrder and user:

from django.contrib.auth.models import User

class PurchaseOrder(models.Model):
   product = models.CharField(max_length=256)
   vendor = models.CharField(max_length=256)
   dollar_amount = models.FloatField()
   purchase_date = models.DateField()
   notes = models.TextField( null=True, blank= True)
   purchased_by = models.ForeignKey(User)

Then you need add a custom Admin class in the admin.py:

class PurchaseAdmin(admin.ModelAdmin):
   list_display = [..., 'purchased_by',...]

It should show up a groupbox that allow you to assign the purchase order to any existing user.

Leave a comment