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
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?
عبدالواسع
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
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
Roy
Have you checked out render? it's also a good one
Nope i haven't checked it yet . All i have used till now is pythonAnywhere and netlify
Pandu
Have you checked out render? it's also a good one
render puts our project to sleep every15min 😐
michael
render puts our project to sleep every15min 😐
For real... Never experienced such lol
michael
Nope i haven't checked it yet . All i have used till now is pythonAnywhere and netlify
How are they so far and why don't want to use them for this project
Roy
How are they so far and why don't want to use them for this project
I wanted to use pythonAnywhere, it's super simple . But then just started to look for better options that's why
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?
Cloud
Hello AUC, I find a uploadimage for send and image.
Abhi
Yeah, you can, you need to setup your website to allow upload either from the admin or from the user account
Recently we upload product manually I want to be that it will change by Excel
Miracle
Recently we upload product manually I want to be that it will change by Excel
If you have access to the codebase, then you can leverage on ORM to easily upload product using excel
Trace
Anyone working on a machine learning deployment using django here?
Artem
Thanks!
Cloud
Hello Team , How I can fix this issue: https://ibb.co/zfRqWZ0
michael
If you have access to the codebase, then you can leverage on ORM to easily upload product using excel
I was thinking of a python selenium script to read the excel data and automate uploading to the website
Miracle
I was thinking of a python selenium script to read the excel data and automate uploading to the website
That will be slow when compared to adding the upload logic inside the backend. Once the backend supports it, it can be well integrated
michael
That will be slow when compared to adding the upload logic inside the backend. Once the backend supports it, it can be well integrated
I initially thought he wants to automate entry of data..Yeah now that makes sense if he has access to the codebase didn't see this one...
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?
Wissam
You can use this or use Import os os.path.join(BASE_DIR, "templates")
Thanks, I did that. I am just asking about the syntax. isn't that a python list? how can we concatenate BASE_DIR, /, and "templates" like this?
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?
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.
razor X
Ok thanks
Jitxs
I have deployed fastapi on render.com
i see i have never tried that.. i'm also a beginner
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?
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?
Miracle
what is the best Django course for complate and fast learning?
Sorry it doesn't exists. You need to take your time and understand the framework else you will spend longer time debugging your codes for errors that you introduced
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
what is the best Django course for complate and fast learning?
U can check Jose Portilla on udemy If u have knowledge of atleast css and html and python That would be enough to grasp the basics
Mahnoosh
Sorry it doesn't exists. You need to take your time and understand the framework else you will spend longer time debugging your codes for errors that you introduced
It's true, but what I meant by "fast" was that the course be optimal and not be long and boring by saying unnecessary things
Miracle
It's true, but what I meant by "fast" was that the course be optimal and not be long and boring by saying unnecessary things
Lol. Actually there are no unnecessary things in programming. What people pay for in consultation could be something you get free when you listen to those unnecessary things being said during the learning phase. What I will advice is, you should utilize the best way you learn to look for materials, if you mean fast, you can consult the documentation, as you can easily search for what you want and see examples
Igor👨‍💻
How can i learn django to replace flask in my HTML websites?
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
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