skip to Main Content

Html – How to create instance of a django model

views.py def create_post(request): profile_inst = Profile.objects.filter(author_real=request.user).first() print(profile_inst) if request.method == 'POST': print('POST request') form = CreatePost(request.POST,request.FILES) if form.is_valid(): print(request.FILES) form.save() else: print('JUST a VISIT!') form=CreatePost(initial={'author':profile_inst}) return render(request,'create_post.html',{'form':form}) ValueError at /create_post/ Cannot assign "'username | admin'": "Post.author" must be a "Profile"…

VIEW QUESTION

Mysql – Slow performance when order by field in foreign key

When a queryset is sorted by a field in a related model performance decreases drastically. I use mysql. For example, I have two models: class Event(models.Model): idEvent = models.BigAutoField(primary_key=True) created_at = models.DateTimeField(db_index=True, verbose_name=_('date')) processed_at = models.DateTimeField(auto_now_add=True, verbose_name=_('processed')) data = models.TextField()…

VIEW QUESTION
Back To Top
Search