Ok, i have this django app, where the user fills in their detail and then create a web profile(username and password)
from django.db import models
class UserDetail(models.Model):
first_name = models.CharField(max_length=225)
middle_name = models.CharField(max_length=255, blank=True, null=True)
last_name = models.CharField(max_length=255)
email = models.EmailField()
def __str__(self):
return self.first_name
class WebDetail(UserDetail):
# user = models.OneToOneField(UserDetail, on_delete=models.CASCADE, primary_key=True,)
username = models.CharField(max_length=255)
password = models.CharField(max_length=255)
and when i create a user that has a webdetail, it shows empty in the database(django admin)
I need help to link the WebDetail to inherit from the userdetail and also they could show up in the database(django admin)
Thanks for your contribution:)
I found this article on model inheritance and there was this comment at the end of the article that stated the following:
"Whoever is reading this in the future make sure you add the following method to each product type class eg:
class Label(Product):
objects = LabelManager()
class Meta:
proxy = True
def save(self, *args, **kwargs):
self.product_type = 'Label'
return super(Label, self).save(*args, **kwargs)
Otherwise you won't be able to see your object after it's creation. Cheers:)"
Here's the link to the article. It's all on model inheritance and it looks like the above code should help with your problem of an empty database after you create a user that has a WebDetail. I would try adding something similar to your WebDetail class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.