Reputation: 35
I have a little problem with my 'id'. I don't know how to do to get the correct id.I have tried to do this in many ways but stil dont have idea.
MODELS
class Projekt(models.Model):
nazwa_projektu = models.CharField(max_length=200, unique=True)
opis_projektu = models.TextField()
zdjecie_projektu = models.ImageField(default='project_photo/default.jpg', upload_to="project_photo",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
wlasciciel = models.ForeignKey(Profil, on_delete=models.CASCADE)
opcja_nr1 = models.CharField(max_length=100, default="111-222-333", blank= True, null=True)
opcja_nr2 = models.CharField(max_length=100, default="[email protected]", blank= True, null=True)
opcja_nr3 = models.CharField(max_length=100, default="www.TwojaNazwa.com", blank= True, null=True)
social_facebook_p = models.CharField(max_length=300, blank= True, null=True)
social_www_p = models.CharField(max_length=300, blank= True, null=True)
social_instagram_p = models.CharField(max_length=300, blank= True, null=True)
social_twitter_p = models.CharField(max_length=300, blank= True, null=True)
social_other_p = models.CharField(max_length=300, blank= True, null=True)
social_likedin_p = models.CharField(max_length=300, blank= True, null=True)
wybor_projekt = models.CharField(max_length=100, choices=wybor_t_f, default="FALSZ")
id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True, editable=False)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return str(self.nazwa_projektu)
class Srodek(models.Model):
wlasciciel = models.ForeignKey(Profil, on_delete=models.CASCADE)
tytul_informacje = models.CharField(max_length=200)
dodatkowe_informacje = models.TextField()
slider = models.ImageField(default='project_photo/default.jpg', upload_to="inside_photo",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
baner = models.ImageField(default='project_photo/default.jpg', upload_to="baner",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
reklama_1 = models.ImageField(default='project_photo/default.jpg', upload_to="ad_1",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
reklama_2 = models.ImageField(default='project_photo/default.jpg', upload_to="ad_2",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
reklama_3 = models.ImageField(default='project_photo/default.jpg', upload_to="ad_3",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
reklama_4 = models.ImageField(default='project_photo/default.jpg', upload_to="ad_4",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
reklama_5 = models.ImageField(default='project_photo/default.jpg', upload_to="ad_5",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
reklama_6 = models.ImageField(default='project_photo/default.jpg', upload_to="ad_6",blank= True, null=True,validators=[FileExtensionValidator(['png', 'jpg', 'jpeg','gif'])])
stopka_firmy = models.CharField(max_length=150, blank=True, null=True)
wybor = models.CharField(max_length=100, choices=wybor_t_f, default="FALSZ")
projekt = models.OneToOneField(Projekt, on_delete=models.CASCADE)
def __str__(self):
return str(self.tytul_informacje)
VIEWS
def ProjektView(request, pk ):
profil = Profil.objects.get(user=request.user)
projekt = profil.projekt_set.all()
srodek = Srodek.objects.filter(id=pk)
if request.method == "POST":
form = OptionsForm(request.POST or None, request.FILES or None)
if form.is_valid():
form.save()
template_name = 'viewProjekt.html'
context = {
'projekt':projekt,
'srodek':srodek,
}
return render(request, template_name, context)
If i tried srodek = Srodek.objects.all()
this works but dont fine, becouse each Projekt has the same Srodek
Demonstrative Photo
Upvotes: 0
Views: 91
Reputation: 563
You need to change the variable name of id, id is a built in function in python that returns the identity of an object. I think this is the cause of your error.
You second error is its expecting a hexadecimal string and you are not providing one in the correct format. You need to convert the string given from the from to a hexadecimal format.
Upvotes: 1
Reputation: 35
I dont think so that problem, is in uuid.uuid4. I tried uuid.uuid4().hex. If i use uuid.uuid4 all was good. http://127.0.0.1:8000/projekty/view_projekt/bd7ce422-1951-4225-8099-37e15e9ac2cf/
. This work correct, but when i try update i have this problem with uuid
Upvotes: 0
Reputation: 35
I fix this "srodek = Srodek.objects.filter(projekt_id=pk)", but i got next problem... When i use option update, i got next error "['“3” is not a valid UUID.']"
Upvotes: 0