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.
- [Answered ]-UpdateView form pre-populate error
- [Answered ]-Python: Parsing Timestamps Embedded in Filenames
- [Answered ]-Django Debug Toolbar Causes Loss of Static Files
- [Answered ]-How to use nested lookup in django?
- [Answered ]-Django Rest Framework adding 2 numbers
Source:stackexchange.com