LB (Ben)
how to use django-treebeard with Django Rest Framework
Ok. What are you trying to do on the Rest side? For example - return a List of children based on a supplied ID?
Anonymous
create an Category for Product and show the product of last child of category http://example.com/category/slug/slug
LB (Ben)
create an Category for Product and show the product of last child of category http://example.com/category/slug/slug
Note. Probably better to keep replying on the original thread. Anyway - if you haven't already, I recommend you read the docs in full. https://django-treebeard.readthedocs.io/en/latest/api.html Create a Category new_category = Category.get_root().add_child(name='foo', slug='foo') not sure on your product model, but assuming you have a foreign key to your Category model, you can then create the Product with a reference to the Category. Show Products in the last child of Category Products = Category.get(slug='some-parent').first().get_last_child().products
Anonymous
What do you mean? Treebeard is a library to work with and store tree structured data.
new_category = Category.get_root().add_child(name='foo', slug='foo') written in serializer or viewSet ? and whats about the url ?
LB (Ben)
new_category = Category.get_root().add_child(name='foo', slug='foo') written in serializer or viewSet ? and whats about the url ?
It's up to you where you want to put that code. The ViewSet methods probably make more sense for creating a category. The Seralizer probably makes more sense for resolving the Treebeard node into data your response needs. I recommend you get it working first, then worry about making the code fit into the right boxes. Doing both at once will be harder.
LB (Ben)
how to use django-treebeard with Django Rest Framework
Good luck. Try to break down the problem into small parts and do one at a time. Once you have that small step working - save your code (write a commit in git for example) then move onto the next step.
Harry gorilla
Why is django loved over other python web frameworks?
Anshu
Yousef
Hello Please help me to solve my problem, I installed Django on pycharm, but when i write 'python manage.py runserver', had this 👇 error python: can not open file 'manage.py': [Errno 2] No such file or directory. I tried to change location of my made file 'djangoProject', but that error is occured
Anonymous
I want to use redis as db to handle shopping cart ,have a doc about it?
Yousef
Go to the dir, where is your manage.py
Execuse me, i thaught manage.py there is in my 'djangoProject' file, but now i see, there is not
Alireza
Execuse me, i thaught manage.py there is in my 'djangoProject' file, but now i see, there is not
So you can recreate your project But if it is not possible to you, you can cooy and paste another file and customized it Of course if it is the only missed file
Shukurillo
from django import forms class NameForm(forms.Form): your_name = forms.CharField(label='Your name', max_length=100) In the situation above, should I create a model for the form?
👑 Dharmzeey
Good Evening Everyone. Please I need help with my code. I am trying to access an attribute of a ForeignKey from a model which I imported. Please how can I access it. Tho I can access it with the dot (.) operator in the shell Terminal But I want to be able to access it in my Editor and assign it a value. Below is the pasteBin
👑 Dharmzeey
https://pastebin.com/anKW1gPQ
Dot enum
I need help in simple_history package
Nenavath BADYA
Good evening my friends, I had completed MCA in 2011, now I am preparing django software developer . Friends anyone give me a suggestion I have a chance to join in IT sector.
Nenavath BADYA
It is possible please help me any ones.
Nenavath BADYA
Dear I want to put six years experience
Dot enum
ask specific question
I'm not able to get changed by username from history, when edit is being made from frontend but it's happening when it's being changed or created from django admin
Doragonsureiyā
I'm not able to get changed by username from history, when edit is being made from frontend but it's happening when it's being changed or created from django admin
Please provide a full explanation including all the details that you consider relevant. Your statement is too broad and there is no clear way to answer you, you have to explain: - what you're doing - what you're expecting - what you're using - where you're running the script - what Python version you're using - what packages and their versions you're using - and the most important thing: show the code YOU wrote (read rule 5️⃣ for that) and more details, that way your chances to get help will increase
Mark
Hi, can i ask some lammer questions?
Mark
I would like to make a model for keeping geographic coordinates. Which in the administrative panel would work as a search bar with an interactive map and placemark. In minimal style keep only latitude and longitude, in advanced style full address if available. The whole garter to openstreetmap. In general, I am worried about how to make a search string that would send GET requests to openstreammap
👑 Dharmzeey
Thanks everybody
pavan
Hello All, Iam working on a Python django project on Excel sheet.I want some help.
pavan
I had given an edit button for each row if I click on it, it manipulate the thing in the particular row but it didn't works.Instead it opens new row.
Fan / Ac
i have a tcp server which is always open and i need to display the data received on the server on django app, whats a good way to do this, i can do db insert on tcp server and db retrieve on django app what are the other ways ?? confused about how should i send data, should i post data to django app and store it in session and display or make a get api on tcp server and send data on get request
Haha
I need to learn about ACL scripts .. Can anyone help me with suitable resources?
遠遠
Hello, how to update multiple fields via Model.objects.bulk_create(list)
Sr
Hello.. is there anyone knows how to built expense tracker app using django
Sr
Please help me in building expense tracker app
QAM
Hi, Any hint to make date availabilty module in django for tour or any service
LB (Ben)
Hello.. is there anyone knows how to built expense tracker app using django
Best to do a bit of searching first, there are many Expenses apps built with Django already out there + also tutorials. - https://django-expense.readthedocs.io/en/latest/ - https://christosstath10.medium.com/django-expenses-7dfd8fb13fc9 - https://kristian-roopnarine.medium.com/creating-a-budget-web-app-with-django-655369b6d43c - https://github.com/rishank-shah/Income-Expense-Tracker - https://github.com/MicroPyramid/micro-finance
Fan / Ac
whats the way to call an api from a view when both api and view exist in the same app other than by using request
arun.krg
Django admin asks for login after every click , idk how to fix this
Абдулазизов
Hello
Абдулазизов
I need internalization in my blog website. I am having some problem in django model tranlation can someone recommend me something like django model translation that should translate static files too
Абдулазизов
Thanks for your answer ahead #help
Mohammadreza
Hi everyone Is it possible to use djongo in integration with elasticsearch?
Healer
Guys what is the advantage of django over flask, aside from the battery included.
Mirco
Guys what is the advantage of django over flask, aside from the battery included.
admin panel built-in, lots of generic views already there, auth already built in, awesome community etc etc I don't see any reason to use Flask nowadays, FastAPI imho has replaced it in every context where Flask was used
Doragonsureiyā
Oh thanks.
You're welcome! 😊
Rebellion
Exception Type: IntegrityError Exception Value: UNIQUE constraint failed This is the error I'm getting while posting a comment on a blog. User can post only one comment. If he tries to post another comment even on any other blog post, this error occurs. How, I can solve this error? How can one user post comments on multiple blogs..? Thank You..!
Rebellion
models.py class Comment(Model): commenter = ForeignKey(Profile, on_delete=CASCADE) post = ForeignKey(Post, on_delete=CASCADE)
Rebellion
Exception Type: IntegrityError Exception Value: UNIQUE constraint failed This is the error I'm getting while posting a comment on a blog. User can post only one comment. If he tries to post another comment even on any other blog post, this error occurs. How, I can solve this error? How can one user post comments on multiple blogs..? Thank You..!
views.py def post_detail(request, pk): post_instance = Post.objects.get(pk=pk) form = CommentForm() if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post_instance comment.commenter = request.user.profile comment.save()
Rebellion
pls help here....😕
Rebellion
Remove the unique = True from your model. You should control the number of user's comment from your view or ...
models.py class Comment(Model): ..... class Meta: ordering = ('created', ) unique_together = (('commenter', 'post'), )
Rebellion
Remove the unique = True from your model. You should control the number of user's comment from your view or ...
I had this 'unique_together' field in my model... I have removed it, still it shows similar type of error... This time, just with UNIQUE constraint failed: blog_app_comment.id
fateme
I had this 'unique_together' field in my model... I have removed it, still it shows similar type of error... This time, just with UNIQUE constraint failed: blog_app_comment.id
to force the user just have one comment , You should not make your fields unique any way. and be sure you run the migration and migrate .
Rebellion
to force the user just have one comment , You should not make your fields unique any way. and be sure you run the migration and migrate .
Even if I force user to have only one comment for one particular blog, he should be able to put comment on other blog.... But, that's not happening. User can put only one comment on entire blog website.... User is failing to put comment on other blogs once he posted on one blog...
Domain
Hello guys please I'm having some issues understanding something in Django rest framework
Domain
I have a list of users called users_list, I'm trying to iterate over the list and return each user but it doesn't work
Domain
It only returns one user
Domain
Isn't it possible to return all the users?
Ahmet
Isn't it possible to return all the users?
Try queryset = User.objects.all()
Domain
I wrote the user_list myself
Domain
Something like user_list = [ {"name" : "John", "age" : 12}, {"name" : "James", "age" : 13}]
Domain
Then I try to iterate through the list of dictionaries and return each individual element
Mohamad Reza
Show your code!
Kamronbek
Then I try to iterate through the list of dictionaries and return each individual element
If you used for loop, it eventually returns the last object.
Kamronbek
First show your code, and tell what do you want to do clearly with that code
Mister
Hello everyone.
Mister
I have an error in my Django code
Mister
I have an error in my Django code
I want to send a mail with my cpanel mail but I have a mistake
Mister
I send a code
Mister
thanks
Doragonsureiyā
I send a code
To share code or error tracebacks, use a pasting service, like: - https://linkode.org - https://dpaste.org