I'm using the Sites Framework and want to save the current site as the default site
value for one of my models.
Model:
class MyModel(models.Model):
site = models.ForeignKey(
Site,
on_delete=models.CASCADE,
default=Site.objects.get_current()) # THIS IS WHAT I WANT TO DO (DOESN'T WORK)
...other fields...
Is there a way to automatically save the current Site
object as the site
attribute of MyModel
anytime I save a MyModel
instance? Or would I need to do this manually by overriding either the form's or the model's save
method, (or similar override)?
You can set the default site.
models.py
This will only work if you have created a site in your database and also set the
SITE_ID
insettings.py