im have post model and a profile model on profile model i have a OneToOneField this is my profile model:
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
GENDER_CHOICES = [('boy', 'پسر'), ('girl', 'دختر'), ('i prefer not to say', 'ترجیح میدهم نگویم')]
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_picture = models.ImageField(upload_to='profile_pictures', blank=True, default='default.jpg')
name = models.CharField(max_length=30)
age = models.IntegerField(default="0")
birth_day = models.CharField(max_length=30)#DateField(blank=True)
gender = models.CharField(max_length=20, choices=GENDER_CHOICES)
address = models.CharField(max_length=30, blank=True, default="---")
bio = models.TextField(max_length=300, blank=True, default="---")
phone = models.IntegerField(blank=True, null=True)
skills = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
favorites = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
favorite_books = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
favorite_movies = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
favorite_musics = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
favorite_sports = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
and this is my post model:
from django.db import models
# from django.contrib.auth.models import User
from django.utils import timezone
from django.urls import reverse
from taggit.managers import TaggableManager
from user.models import Profile
class Post(models.Model):
STATUS_CHOICES = [('published', 'published'), ('draft', 'draft')]
title = models.CharField(max_length=60)
slug = models.CharField(max_length=120, unique=True)
image = models.ImageField(blank=True, upload_to="posts_images", null=True)
image_alt = models.CharField(max_length=35, blank=True, null=True)
body = models.TextField()
date = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)
publish_date = models.DateTimeField(default=timezone.now)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='published')
author = models.ForeignKey(Profile, on_delete=models.CASCADE)
tags = TaggableManager()
published_manager = PublishedManager()
def __str__(self):
return self.title
class Meat:
ordering = ('-publish_date',)
def get_absolute_url(self):
return reverse('post:post_details', args=[self.slug,])
and i can change the previuos posts and save them but i can't add a new post get this error
IntegrityError at /admin/post/post/add/
NOT NULL constraint failed: post_post.owner_id
you can see that owner_id before i add the profile model i connect djangouser with a foregnkey with post model and its variable was 'owner' but now i deleted but i still get it's error and also when i migrated the new profile i get somethings like error but they was'nt error they was some things like warnings or something like that thanks for helping
Aucun commentaire:
Enregistrer un commentaire