Categories
Mastering Development

django-private-storage configuration in nginx and Docker

I am trying to use django-private-storage package to protect a model’s file from being accessed or downloaded by users who are not owners of the file. I was able to do it successfully in development (using python manage.py runserver) In development, I am using nginx configured via docker. I can create objects with both FileField […]

Categories
Mastering Development

Django forms – nested filtering in a vew for form cleaned data validation

This is related to Filter queryset with multiple checks, including value_is_in array in a Django view, though addresses a slightly different issue. I need two levels of checking of my form data: I have a profile model with name, surname, and role (the last one is and array coming from a related model, one profile […]

Categories
Mastering Development

Show users that liked a post on django

Well, I have one of the functions of my project is to give likes to posts and when that is done the users that liked the post are suposed to apear next to the like count, the problem is that the users dont appear for some reason. I think that error is in the models, […]

Categories
Mastering Development

ValueError at /articles/article/19 The ‘article_image’ attribute has no file associated with it

models.py from django.db import models from ckeditor.fields import RichTextField class Article(models.Model): author=models.ForeignKey(“auth.User”,on_delete=models.CASCADE,verbose_name=”Yazar”) title=models.CharField(max_length=50,verbose_name=”Başlık”) content=RichTextField(verbose_name=”İçerik”) created_date=models.DateTimeField(auto_now_add=True,verbose_name=”Oluşturulma Tarihi”) article_image=models.FileField(blank=True,null=True,verbose_name=”Fotoğraf Ekleyin”) def __str__(self): return self.title detail.html <img class=”img-fluid rounded” src=”” alt=””> when i want add image to my articles i get error and in my vs code it ot creare media folder although i can see my articles […]

Categories
Mastering Development

SQL /peewee. How do I update a record based on condition from another table?

So I am trying to update a store after an item is bought. These are the models I’m working with. class Cart(): user = pw.ForeignKeyField(User, backref=”cart_user”, null=True) item = pw.ForeignKeyField( Item, backref=”cart_item”, null=True, on_delete=’SET NULL’) payment_status = pw.BooleanField(null=False, default=False) payment = pw.ForeignKeyField(Payment, backref=”payment”, null=True) amount = pw.IntegerField(null=False, default=1) class Item(): name = pw.CharField(null=False) product_type = […]

Categories
Mastering Development

Add multiple models and custom fields to a json response in Django Rest Framework

i’m new into Python/Django programming and i got stuck with something in a personal project that i’m doing. My issue is that i want to return a custom response based on different models of my application, some of the values will come from custom queries and others are part of the models itself. So, i […]

Categories
Mastering Development

Django import export – How to skip the new rows, and only update the existed ones

When importing a file I want to skip all of the new rows that doesn’t exist, and only update and change the ones that already exists, I’ve been trying for days to solve this problem, any ideas will help. https://ibb.co/1Gw4Q19 also the file type is “.xls” or “.xlsx” here’s my code: models.py: class Author(models.Model): name […]

Categories
Mastering Development

auto-populate Model B with the data from Model-A and/or Model-C

firstly abstractly speaking – each time i create an order via Model A i want to auto-populate Model B with the data from Model-A and/or Model-C. now straight to the point – i want both, the customer’s name & the product (which they are purchasing) to automatically appear as a concatenated string in the third […]

Categories
Mastering Development

Django Admin tabularInline very slow request

I have Location app in my project. There are list of countries, their states and cities. model.py class Country(models.Model): class Meta: verbose_name = ‘Country’ verbose_name_plural = ‘Countries’ unique_together = [‘name’, ‘iso2’], name = models.CharField( max_length=255, verbose_name=_(‘Country name’), ) iso2 = models.CharField( max_length=2, null=True, blank=True, verbose_name=_(‘iso2’), ) phone_code = models.CharField( max_length=15, null=True, blank=True, verbose_name=_(‘Phone code’), ) […]

Categories
Mastering Development

Directing Output Paths of Altered Files

How can I direct the destination of the output file to my db? My models.py is structured like so: class Model(models.Model): char = models.CharField(max_length=50, null=False, blank=False) file = models.FileField(upload_to=upload_location, null=True, blank=True) I have the user enter a value for ‘char’, and then the value of ‘char’ is printed on to a file. The process of […]