I'm new to Django. Can anyone out there for the rescue.
In my current proect, I've couple of models inside a Django app: Project, ProjectMember. Here's their model and admin structure.
models.py
class Project(models.Model):
name = models.CharField(max_length=100)
start_date = models.DateField()
end_date = models.DateField()
description = models.TextField(max_length=1000)
class ProjectMember(models.Model):
project = models.ForeignKey(Project, on_delete=models.SET_NULL, null=True)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
admin.py
from .models import Project, ProjectMember
class ProjectMemberInline(admin.TabularInline):
model = ProjectMember
extra = 0
class ProjectAdmin(admin.ModelAdmin):
list_display = ('name', 'start_date', 'end_date')
inlines = [ProjectMemberInline]
admin.site.register(Project, ProjectAdmin)
What I want to achieve is, every Project(i.e. model) should have unique users(ProjectMember) and every user can be associated with multiple projects. But with the current structure, system allows duplicate ProjectMember insertion in the admin. Please see the screenshot, I've add here 2 same users.
Any help is appreciated.