I have two models inn my django application where I have ManyToMany field in one model to other. I want to set the default for ManyToMany field but getting no way to do this.
My models are
Class Model1(models.Model):
name = models.CharField(max_length=100)
class Model2(models.Model):
model1 = models.ManyToManyField(Model1, null=True, blank=True, default=Model1.objects.first())
but using this I am getting this error
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I tried it by defining an explicit variable also like
m1 = Model1.objects.first()
and assigning this m1 variable to the field as default but same error again.
Please suggest how can I assign default value to the M2Mfield in django. I want that the first object of the choices should be selected when the modelform renders on template.