Ankit Sharma
I have multiple apps when I log in I wanna switch between apps
.
Husen
AttributeError: Got AttributeError when attempting to get a value for field `image` on serializer `PostDetailSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Post` instance.
Original exception text was: 'Post' object has no attribute 'image'.
Hello everybody. The gallery model is connected to the post model as a foreginkey, now when I try to make a post detail, I get this error
Charly
Thinking
Hello. Does anyone know how I can backup the database in django? I'm new and learning with the Django manager.
Charly
Thinking
thank you. What I want is for the system administrator to be able to backup the database. click and download. Is there any solution for this?
Charly
عبدالواسع
when I try to add an employee from Rest Api it show error:
raise ValueError(
ValueError: Cannot assign "<Salary: 500>": "Employee.salary" must be a "Salary" instance.
class Salary(models.Model):
amount = models.IntegerField(_("الأجر اليومي"))
date_from =models.DateField(_("تاريخ الإنضمام"))
date_to = models.DateField(blank=True,null=True)
class Employee(models.Model):
name =models.CharField(_("الأسم"),max_length=200)
salary = models.OneToOneField(Salary,verbose_name=_("الأجر اليومي"),on_delete=models.CASCADE)
user = models.ForeignKey(Profile,on_delete=models.CASCADE, related_name='employees')
class Meta:
ordering = ['name']
serializers:
class SalarySerializer(serializers.ModelSerializer):
class Meta:
model = Salary
fields = ['amount', 'date_from', 'date_to']
class EmployeeSerializer(serializers.ModelSerializer):
salary = SalarySerializer()
class Meta:
model = Employee
fields = ['name', 'salary']
def create(self, validated_data):
salary_data = validated_data.pop('salary')
salary = Salary.objects.create(**salary_data)
employee = Employee.objects.create(salary=salary, **validated_data)
return employee
views:
class EmployeeCreateView(generics.CreateAPIView):
queryset = Employee.objects.all()
serializer_class = EmployeeSerializer
json:
{
"name": "Ali",
"salary": {
"amount": 500,
"date_from": "2024-01-01",
"date_to": "2024-12-31"
}
}
Alex
when I try to add an employee from Rest Api it show error:
raise ValueError(
ValueError: Cannot assign "<Salary: 500>": "Employee.salary" must be a "Salary" instance.
class Salary(models.Model):
amount = models.IntegerField(_("الأجر اليومي"))
date_from =models.DateField(_("تاريخ الإنضمام"))
date_to = models.DateField(blank=True,null=True)
class Employee(models.Model):
name =models.CharField(_("الأسم"),max_length=200)
salary = models.OneToOneField(Salary,verbose_name=_("الأجر اليومي"),on_delete=models.CASCADE)
user = models.ForeignKey(Profile,on_delete=models.CASCADE, related_name='employees')
class Meta:
ordering = ['name']
serializers:
class SalarySerializer(serializers.ModelSerializer):
class Meta:
model = Salary
fields = ['amount', 'date_from', 'date_to']
class EmployeeSerializer(serializers.ModelSerializer):
salary = SalarySerializer()
class Meta:
model = Employee
fields = ['name', 'salary']
def create(self, validated_data):
salary_data = validated_data.pop('salary')
salary = Salary.objects.create(**salary_data)
employee = Employee.objects.create(salary=salary, **validated_data)
return employee
views:
class EmployeeCreateView(generics.CreateAPIView):
queryset = Employee.objects.all()
serializer_class = EmployeeSerializer
json:
{
"name": "Ali",
"salary": {
"amount": 500,
"date_from": "2024-01-01",
"date_to": "2024-12-31"
}
}
there is some error in salary object creation.
Alex
or in data being saved
RAEKEN
Guys, is possible to link a template page in an app to another template page in a different app
Tanjiro
Hi good day. I need help in my modals because my view payslip action wont display the view_payslip form, it just returned a JS pop up saying "127.0.0.1:8000: says error" Please I need your help and guidance. I am using python and django
https://dpaste.org/GqBdw
Believe
Is someone is good at Websocket I am stuck in a project. It is complicated. If anyone can help me I can pay also for that
Roy
I want to deploy my django application . It's a simple e-commerce application which consists paypal payment integration .
Which hosting platform should I use python anywhere or hostinger vps hosting ?
Which one should I use ? please let me know
Pandu
Roy
Yeah it's no problem. I am ready to purchase plan . I am just looking for something which can be easy to deploy and good performance .
Pandu
performance pov,
idk,
ig all works similar
as long as it's having less visitors.
is it for real use?
or just personal project
michael
Roy
Pandu
michael
michael
Rasoul
Real use
Then just use something like AWS or Heroku. Yes, there could be a learning curve, but it's worth it.
Abhi
I want know about something can we add product in e-commerce by using Excel because if we do manually that's takes lot of time
Also in future we will change the images of product, name, description, size, category?
Cloud
Hi everyone,
Can someone help me with importing Tailwind CSS? I can't figure out why it's not working for this page. What information do you need to do a check?
Auc
Cloud
Hello AUC, I find a uploadimage for send and image.
Auc
Miracle
Abhi
Trace
Anyone working on a machine learning deployment using django here?
Tererai Tyler
Artem
Thanks!
Swapnil
Cloud
Hello Team , How I can fix this issue: https://ibb.co/zfRqWZ0
Miracle
Wissam
Hello good people
I started learning django yesterday so sorry if my question is stupid
I have read that if I want to make django consider directory called "templates" I should add the following to in settings.py :
# django_project/settings.py
TEMPLATES = [
{
...
"DIRS": [BASE_DIR / "templates"], # new
...
},
]
So how can we write something like this. isn't that a python list? how can we concatenate BASE_DIR, /, and "templates" like this?
Benso
Benso
Yes. Then place templates in the root directory.
Ethan
no, don't worry about it
Wissam
I know but my question is this: we concatenate strings like this in python: "Hello, " + "World!". my question is how did we concatenate strings without a plus sign here?
Miracle
razor X
I had made APIs in fastapi and want to use django for templating, all the data are stored in mongodb so what should I do for login function, I can make session variables and use it to check if logged in , userid, etc but should I do these things or there should be other approach.
I am beginner so please help.
Charly
razor X
Ok thanks
Jitxs
razor X
ZeroCool
Hi everyone, has anyone had this case? I have a Django project running on localhost:2000 (main project), I have another Django project on localhost:8000 (child project), this last project has no user table, so to generate a token, I send the credentials to the main project , I receive the token in HS256, but when I pass the token when making a request to the secondary project I have an error that it is not valid or that it has already expired, there have been cases in which a Django project does not have a user table but you want give security to your api? What other method do you apply?
Rud
Hi everyone, i have several tables in the webpage ( and have some selected options to filter the report data that i need based in category date type etc)
Solution 1 once filtered and click submit button -> send post request to django then return the filtered data using Redis ( cons: when user select other option and submit, redis will re-get again right? )
Solution 2 once filtered and click submit button -> filtered in the client side directly , so we put jsonresponse into another url (all json data in that url), then in client side we fetch it the url and filter it using javascript
which one is better ya and normally what’s the suitable attempt ya?
Miracle
northern
like this
Charly
Because errors are text. Read rule 5 to know how to send it.
Mahnoosh
what is the best Django course for complate and fast learning?
Prapti
https://stackoverflow.com/questions/78502294/how-the-privatefilefield-handles-validators-in-django
I have a question guys, can someone please answer to my query.
Venkatesh Akhouri
Mahnoosh
Mahnoosh
Mahnoosh
Igor👨💻
How can i learn django to replace flask in my HTML websites?
Alex
Sam
guys i want to add a feature which gathers the price of a product for a considered time (for example 30 days)
What`s the best way to do this?
shall i create a field or model name ProductPrice and keep the price`s changes in it ?
Chaitanya
You can keep a separate model for storing price and datetime which can be refer for getting price as per date or latest as per filters and other possibility
Sam
Sam
model:
class ProductPrice(models.Model):
product = models.ForeignKey(Product, models.CASCADE)
change_time = models.DateTimeField(auto_now_add=True)
price = models.IntegerField(null=True, blank=True)
method:
def get_price_for_past_30_days(self):
thirty_days_ago = datetime.now() - timedelta(days=30)
product_prices = ProductPrice.objects.filter(product=self, change_time__gte=thirty_days_ago)
prices = []
for product_price in product_prices:
prices.append(product_price.price)
return prices
Sam
in addition i used save method to create a new instance whenever i changed the price of my product
Sam
def save(self, *args, **kwargs):
if self.pk:
created = True
else:
created = False
if self.title:
self.slug = slugify(self.title, allow_unicode=True)
if self.discount_percentage and self.discount_percentage > 0:
self.discount = True
elif not self.discount_percentage or self.discount_percentage <= 0:
self.discount = False
else:
return
super(Product, self).save(*args, **kwargs)
if created is True:
if self.price != self.original_price:
ProductPrice.objects.create(product=self, price=self.price)
Ameth
hello i need help for error : integrity error on django-admin
ruthless
You need to change type int to str