In the Django model, one django user shall have many devices (one to many relation). This device shall have a globally(!) unique mac address, which means no other user has a device with that mac address. Thats why I used "unique = true" which is easy. But how do I allow one user to choose the devicename freely but with the restriction that the chosen devicename is just allowed once for himself (not globally unique, just for this single user). What I mean is, there can be two Users "UserA" and "UserB", both can name their device "pikachu" but "UserA" must not call a second device of his "pikachu" again.
This is my model.
from django.db import models
from django.contrib.auth.models import Userfrom datetime import date
from django.db.models.signals import post_save
class Device(models.Model):
user = models.ForeignKey(User)
mac = models.CharField(max_length=17, default='00:00:00:00:00:00', unique=True)
devicename = models.CharField(max_length=20, default='', unique=True)
Any ideas?