G
and this is what i get when i send the request from front-end
Take a look at this maybe it's useful. I think that your problem is related with the permissions, so look this https://www.django-rest-framework.org/api-guide/permissions/
Anders (izzno / gooood) 🇳🇴
Hey @pyflare you up for some mentoring ?
Anders (izzno / gooood) 🇳🇴
Multiple pictures on a model
Anders (izzno / gooood) 🇳🇴
It's bugging the life out of me...
Anders (izzno / gooood) 🇳🇴
Im still not sure how I can get multiple pictures done in one create view in the admin app.
Anders (izzno / gooood) 🇳🇴
Mentoring for ?
Is this what youre thinking of ?
Anders (izzno / gooood) 🇳🇴
Its a huge project, I cant share that here. I could give you access on github ?
Anders (izzno / gooood) 🇳🇴
The link I shared i get, you inject a form that lets you upload pictures and then you connect them when you override the save method in admin.py ( I had no idea you could do that )
Anders (izzno / gooood) 🇳🇴
I could just save the pictures with a "related_name=" and i could sort/find them easally .
Mirco
Its a huge project, I cant share that here. I could give you access on github ?
Could you share just the snippet related to uploading mutliple images ?
Anders (izzno / gooood) 🇳🇴
Mirco
The link I shared i get, you inject a form that lets you upload pictures and then you connect them when you override the save method in admin.py ( I had no idea you could do that )
Ah ok 😂 Anyway I can tell one of the code flow in a classic view when you have Item and ItemImage as models When you upload multiple images , in the request object you can get them via request.FILES.getlist("name_of_input") and loop it to create ItemImage objects
Anders (izzno / gooood) 🇳🇴
Ah ok 😂 Anyway I can tell one of the code flow in a classic view when you have Item and ItemImage as models When you upload multiple images , in the request object you can get them via request.FILES.getlist("name_of_input") and loop it to create ItemImage objects
Yeah, i got that now reading the "russian" post. I think what went wrong is I had no idea you could override the ADMIN save method, and so I thought you were talking about he MODEL save method ;)
gamer_boy
hi guys, i stuck in problem .... i was learning 'template extending ' chapter for that i created new view called 'detail' and added a path for that view in stories/url.py and refresh website(i was expecting'TemplateDoesNotExist' error ,cause i have not created template for that page ) but instead showing error,my previous page template got rendered.and even after creating 'detail template', previous page template is still getting rendered
gamer_boy
http://dpaste.com/0AMTRZT -detail.html
gamer_boy
http://dpaste.com/1SVRMQV- app/url.py
gamer_boy
http://dpaste.com/1XVMPNY -views.py
gamer_boy
plz help me
Mirco
plz help me
Share settings
Anders (izzno / gooood) 🇳🇴
I keep getting: TypeError: expected str, bytes or os.PathLike object, not NoneType https://pastebin.com/8Jzzvbse
Mirco
Are you sure pictures is the name of ImageField ?
Anders (izzno / gooood) 🇳🇴
Never mind
Anders (izzno / gooood) 🇳🇴
I think I screwed up the return from the upload_to function.
Anders (izzno / gooood) 🇳🇴
It's not prepared for this class ;)
Mirco
Full traceback could me clearer
Anders (izzno / gooood) 🇳🇴
It works now
Anders (izzno / gooood) 🇳🇴
All you need is the model inline, no need to override the save...
Mirco
All you need is the model inline, no need to override the save...
Good! 😁 Remember that you need to pass pk of parent model when creating images to link them to it
Anders (izzno / gooood) 🇳🇴
https://pastebin.com/nBaryszA
Anders (izzno / gooood) 🇳🇴
appaearently i dont have to do that, this works
Mirco
appaearently i dont have to do that, this works
Cool, less code 😁 I've still not used so much inlines ☹️
Anders (izzno / gooood) 🇳🇴
Whats anoying is I dont understand how it gets the pk
Mirco
Mmm you should check official docs for better explanation
Anders (izzno / gooood) 🇳🇴
It's comferting that you dont know either ;)
Anders (izzno / gooood) 🇳🇴
Thanks for playing ball Mirco... It helpes to have someone to "play ball" with ;)
gamer_boy
Share settings
http://dpaste.com/238ZTJF
Anders (izzno / gooood) 🇳🇴
Mmm you should check official docs for better explanation
It's becouse the fieldname (item) on my inline model (ItemPicture) matches the parent model: https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.TabularInline So I have my self to thank for using good practice and django to thank for makes it super intuitive...
Anders (izzno / gooood) 🇳🇴
Genious... Django that is...
Mirco
http://dpaste.com/238ZTJF
You have to specify dirs where find templates or Django will look for into your app dir
Anders (izzno / gooood) 🇳🇴
I threw that in a comment in the model, I will never remember that... :D
m
Or this most specific https://www.django-rest-framework.org/api-guide/permissions/#how-permissions-are-determined
thant is interesting thanks a lot, but the requests are done by the same user who is already a superuser
Anders (izzno / gooood) 🇳🇴
@pyflare https://pastebin.com/nBaryszA Look at the serializer... This is all it took to add the pictures... awsome.
Anders (izzno / gooood) 🇳🇴
https://pastebin.com/nBaryszA
inchidi
https://pastebin.com/nBaryszA
you still working on your django admin site?
Akash
I have this particular Model say: Relation with 2 column: Parent | Children And here are some example entries: A | B A | P B | C C | D D | E P | Q R | S I am trying to use ModelManager to validate any new entry so no circular relation should happen. Suppose I try to enter new Relation E | A I will call Relation.objects.is_relation_possible(E, A) It should return False as E cannot be Parent of A. Similarly, Q cannot be a parent of A But R and S can be a parent of A or any other. Is there any easy way other than looping over each parent of every immediate parent..
Anders (izzno / gooood) 🇳🇴
you still working on your django admin site?
no, this is the API representation of the pictures after i used multiple pictures.
inchidi
no, this is the API representation of the pictures after i used multiple pictures.
oh i thought you costumize your admin page til at level where your django admin pages restful lol
Anders (izzno / gooood) 🇳🇴
hahahaha... no no...
Anders (izzno / gooood) 🇳🇴
Im not writing the front end... Thank god...
Anders (izzno / gooood) 🇳🇴
On another note, i cant believe I forgot about inline's... incredibly usefull
Akash
how is your is_relation_possible() looks like?
Thinking something like this: class RelationManager(models.Manager): def relation_not_possible(self, group_id, parent_id, children_id): person = Person.objects.get(pk=parent_id) return person.child_relations.filter(parent_id=parent_id, group_id=group_id).first() class Relation(models.Model): group_id = IntegerField(null=True) parent = ForeignKey(Person, related_name="parent_relations", on_delete=models.PROTECT) children = ForeignKey(Person, related_name="child_relations", on_delete=models.PROTECT) objects = RelationManager() class Meta: unique_together = ('group', 'parent', 'children')
inchidi
For readability https://pastebin.com/r6QNVi6i
is this method produce result like what you want already?
inchidi
seems like not tho
Akash
seems like not tho
yes it doesn't I tried to re-write it quick to send some code... I was trying a for loop but thatt only covers one level parent
gamer_boy
my app url is not working
gamer_boy
http://dpaste.com/0VQ7BSP -myapp/urls.py http://dpaste.com/3YTSSR2 -project/urls.py
gamer_boy
plz help me
inchidi
i cant give you "easier way" if i dont even know what to compare tho
Вадим
Hello, it is a possible to create a widget (or live-chat) based on Django? If it is possible, i try to find examples\courses for this problem. Thank for atention!)
Akash
i cant give you "easier way" if i dont even know what to compare tho
Nvm got it solved using get_all_parents and get_all_children methods on Person model
Ghorz
https://dpaste.de/DiNf i had difficulty calling objects.consignment.timeline in my template, it returns consignment.Timeline.None
Ghorz
how can i solve it