Anders (izzno / gooood) 🇳🇴
The product wont exist when you add the pictures.
Anders (izzno / gooood) 🇳🇴
untill you hit save.
Mirco
That's why you need to create it but don't commit before creating images
Anders (izzno / gooood) 🇳🇴
Mirco
Is this possible in the admin app ?
admin app is not different from another one , it's always an app
Anders (izzno / gooood) 🇳🇴
but I would have to modify the admin app... hehe
Anders (izzno / gooood) 🇳🇴
Is that considered "good practice" ? Butcher the admin app ;)
Mirco
but I would have to modify the admin app... hehe
Nope, just the override the save method of your model
Anders (izzno / gooood) 🇳🇴
Anders (izzno / gooood) 🇳🇴
I will try and better formulate a question
Orack
now ihave started to understand how django works ie what calls what
Orack
confusion remains in when to use what
Anders (izzno / gooood) 🇳🇴
At the moment my models have one img field each. I use a function to sort the file structure: https://pastebin.com/vaYXZzGK What I would like is to be able to add multiple images to some models, like items for intance. If I where to create a model "images" and the coresponding field images in the Items model. Then uppon using the admin site to add images it would open a popup of the "images" model letting me upload images. But how do i automatically decide where those images are stored.
Mirco
Where would you like to store them ? Remember that you will have instance of parent model
Anonymous
Hi... Does anyone here ever create a table input using forms & crispy-forms? I've created one. but it looks like default form styling from crispy itself. how can I make it to the table so the user don't need to scroll down to fill the form
Anders (izzno / gooood) 🇳🇴
Where would you like to store them ? Remember that you will have instance of parent model
items/itemID (instance of parentmodel really? how do i get that ?
Anders (izzno / gooood) 🇳🇴
you are probably missing a filter
Mirco
items/itemID (instance of parentmodel really? how do i get that ?
When you create the product , that's the parent When u save the form before committing, you get the product instance
Anonymous
here's the code https://pastebin.com/GZHgnY37
Anders (izzno / gooood) 🇳🇴
yep...
Anders (izzno / gooood) 🇳🇴
{% load crispy_forms_tags %}
Anders (izzno / gooood) 🇳🇴
at the top
Anonymous
already did. at the top of the file: {% extends "base.html" %} {% load crispy_forms_tags %} {% load static %} {% block content %}
Anders (izzno / gooood) 🇳🇴
your not doing anything with the form
Anders (izzno / gooood) 🇳🇴
form.as_table is not using crispy forms
Anonymous
yes, I've try to use {{form | crispy}} but still, the default style form is from crispy it self
Anonymous
here's my goal, something like this... https://imgur.com/ZQQLEAF
Anonymous
what I got: https://imgur.com/6FqsLi3
Anders (izzno / gooood) 🇳🇴
yes, I've try to use {{form | crispy}} but still, the default style form is from crispy it self
https://django-crispy-forms.readthedocs.io/en/latest/filters.html?highlight=as_p
Anders (izzno / gooood) 🇳🇴
Orack
current_site = get_current_site(request)
Mirco
again how do i do this in the admin view ? Do you have some reference ?
Not at the moment, but you can pass a custom form or save_model to override the default one
Orack
can this be used in serializers
Orack
there is no request variable
Anders (izzno / gooood) 🇳🇴
Not at the moment, but you can pass a custom form or save_model to override the default one
I get that a custom widget could do this, but how will overiding the save method help ?
Anders (izzno / gooood) 🇳🇴
there is no request variable
theres allways a request variable
Anders (izzno / gooood) 🇳🇴
What are you trying to do ?
Orack
trying to add email confirmation
Mirco
Admin site use save_model() method , you need to override it and you have access even to request or form object
Orack
trying to add email confirmation
https://del.dog/e/bezepacunu
Orack
under UserSerializervalidate function
Orack
save_model
isnt there an easier way ? 😐
Mirco
isnt there an easier way ? 😐
It's the easy way 😊
Orack
Orack
only need 'domain': current_site.domain,
Orack
current_site = get_current_site(request)
Anders (izzno / gooood) 🇳🇴
Admin site use save_model() method , you need to override it and you have access even to request or form object
Can you give me an example ? I still dont get how overiding the image save model will change anything as its saved before the item anyway
Mirco
Can you give me an example ? I still dont get how overiding the image save model will change anything as its saved before the item anyway
Just to be sure I've understood 🤣 Your goal is to have a form inside admin site where you can create a Product with one or more images related to it Am I right ?
Anders (izzno / gooood) 🇳🇴
Just to be sure I've understood 🤣 Your goal is to have a form inside admin site where you can create a Product with one or more images related to it Am I right ?
not exactly, I am using the default admin site to add data. ITEMS is one of the models. I want to be able to add more then one picture to the ITEMS model. So if i add a IMAGE model with a relation to the ITEM model, then i create a new ITEM (on the admin site) adding multiple pictures to that ITEM every time I add pictures from the NEW ITEM view it would save that IMAGE model (without any connection to the ITEM model). Unless you are suggesting two steps. 1, add the ITEM, 2 add the pictures with a FK to the Item
Anders (izzno / gooood) 🇳🇴
Bingo. In the same form the admin site provides for the ITEM
Anonymous
https://django-crispy-forms.readthedocs.io/en/latest/filters.html?highlight=as_p
found the solutions. using the tag from crispy itself. by using: {{form.fieldName | as_crispy_field}} thank's mate!.
Mirco
Bingo. In the same form the admin site provides for the ITEM
So what I said before , you just need to refer images to item on pre save
Anders (izzno / gooood) 🇳🇴
So what I said before , you just need to refer images to item on pre save
I'm sure this is super easy if you've seen some code, but I have no clue what that involves 😱
Rounak
Sending media isn't allowed in the group.. Why it is showing
Rounak
In pycharm when i m trying to run python manage.py runserver
Rounak
I am getting this error
Rounak
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Anonymous
Sending media isn't allowed in the group.. Why it is showing
u can use imgur.com. like this: https://imgur.com/6FqsLi3
Anders (izzno / gooood) 🇳🇴
Anders (izzno / gooood) 🇳🇴
You have not set up your environment correctly
Anders (izzno / gooood) 🇳🇴
which depends on a lot of variables
Rounak
While creating the project in pycharm I have used existing interpreter... I hv not used the virtual one...
Anders (izzno / gooood) 🇳🇴
then your existing interpreter does not have django
Rounak
nope if i write django-admin in pycharm ,i m getting available commands...this means it is successfully installed
Rounak
Rounak
But why it is not working in pycharm... Can anyone say... Today I started using django... First day, but found the first issue😭
Anonymous
https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
Rounak
I think u need to learn more about virtual environment
The tutorial that I am following, there they have not used virtual one,there ones is working, why mine is not working
Anonymous
The tutorial that I am following, there they have not used virtual one,there ones is working, why mine is not working
there's behind the scene that we can't see. as I said... read more about virtual environment. it will make much easier to manage ur project. especially python project
Anonymous
if u're using python3, type: python3 -m venv env or python -m venv env
Anonymous
the env is your virtual environment name