Manish
how to achieve this
Rajjix
u don’t need a separate model for featured just add a boolean field
Rajjix
and add a model manager
Manish
this is my model https://del.dog/upepumavas.py
but if i want to do that way then can i get result
Rajjix
if you add a featured boolean field in ur model
Manish
okay can i limit the no. of featured boolean
Manish
like i only want 3 featured items
Rajjix
u can get the last 3 added, first three added
Rajjix
it’s just a matter of what you are querying for
Rajjix
Date added
Rajjix
but instead of writing a long ass filter field, u can use a model manager to make shortcuts for ur searches
Mirco
you can find all info on official docs about models, queries etc.
Mirco
thank you
yw 😄
Anders (izzno / gooood) 🇳🇴
I decided on many boolean fields for attributes...
Anonymous
Not good
Anonymous
Design
Anders (izzno / gooood) 🇳🇴
Whould you rather have foreign keys upon foreign keys?
Anonymous
What
Anders (izzno / gooood) 🇳🇴
My bad
Anders (izzno / gooood) 🇳🇴
Let's say you have an item which can have a set of main attributes which has subattributes
Anonymous
And
Anders (izzno / gooood) 🇳🇴
How would you solve that in a model/s
Anonymous
Create separate relations and use foreign keys
Anders (izzno / gooood) 🇳🇴
Every item has different main / subattributes and can have any combination
Anders (izzno / gooood) 🇳🇴
I'm not sure I follow.
Anonymous
Can you draw an example?
Anders (izzno / gooood) 🇳🇴
You meen create a model attribute, add all the attributes then connect the attributes to the items?
Anders (izzno / gooood) 🇳🇴
Yes, later to night.
Sergei
Hello everybody! I have executed "python manage.py collectstatic" And now it is printing "y" in Terminal. it seems never to stop
ilyandho
Sergei
Could you explain how to bind my css and js files?
George
Could you explain how to bind my css and js files?
Follow the tutorial of django, set the static directory and you can call them from there
Anders (izzno / gooood) 🇳🇴
So what I am trying to achieve is subattributes opens up based on what the user gives it as main attributes (plural, can have sevral main attributes). If this whould be possible in the admin view would be the best option. Else i would have to use ajax and JQuery or simuler.
Anders (izzno / gooood) 🇳🇴
There is another problem as I can not make the attribute objects based on premenition as i can not know all the possible compinations. imagine a car: The user adds a car, color and chooses engine, then gets presented with boolean options for that engine type. I can now the attributes, but not which will apply to what object in what combination.
Rajjix
Could you explain how to bind my css and js files?
should not happen just make sure ur static_root directory is valid, and u have the right permissions to write to it
Rajjix
What about permissions ?
just make sure your static_root is in ur home home directory, and you should be fine
Rajjix
/home/<user_name>/**
Anders (izzno / gooood) 🇳🇴
u have them all preset right? , like an option to choose from .Just sub-options change according to preselected attributes ? or are the sub-attributes based on user input (charfield)
Im trying to figure out how to build that setup, if i should have the subattributes as boolean fields in a main attribute model and then connect that model as a onetoone with the item model.
Anders (izzno / gooood) 🇳🇴
or just have every attribute / subattrbute in the item model, then show them based on what the user chooses as main attributes.
Rajjix
i’m not an expert on this but i have the feeling that manytomany relation is very logical here
Rajjix
many sub attributes can return to many main attributes and vise versa, for each step down your tree structure for attributes u create another model for another subcategory
Rajjix
take two main models for example tshirt and a sweater, each has his separate model, but both have manytomany relation to a saperate color model
Anders (izzno / gooood) 🇳🇴
I need two things. The possibility of an item having attributes/subattributes. Then i need a way for the user to only see, the subattributes of the main attributes he has choosen. Then i need to do tests of what perticular attributes this item has to deliver a ressult. How would you do that ;) ?
Rajjix
take two main models for example tshirt and a sweater, each has his separate model, but both have manytomany relation to a saperate color model
color can then have submodels related to them by manytomany relation one for each color, per say a gray color module that defines different saturation levels of gray, and the tree goes on
Anders (izzno / gooood) 🇳🇴
Im just trying to avoid a model mess :)
Anders (izzno / gooood) 🇳🇴
yes, can you make this different models appear based on choise in the admin view ?
Rajjix
i’m pretty sure you can, but i personally don’t know how 😁
Rajjix
but u can access all parent model for the submodule for example all items that are related to the color gray no matter what they are a sweater or a tshirt
Rajjix
i think item_set.all() is the query for that but i’m not sure
Anders (izzno / gooood) 🇳🇴
My main issue is i cant decide how to connect the mainAttribute, subAttribute and the Item. I can have models for all, but i think the easiest (cleanest) way would be to have a mainAttribute model with booleanfields for subattributes. The "problem" then is I cant ass subattributes on the fly.
R
Not sure, but this maybe could suit you: https://github.com/django-mptt/django-mptt/blob/master/README.rst
R
Have not personally used this package, but have good references from it
Rajjix
My main issue is i cant decide how to connect the mainAttribute, subAttribute and the Item. I can have models for all, but i think the easiest (cleanest) way would be to have a mainAttribute model with booleanfields for subattributes. The "problem" then is I cant ass subattributes on the fly.
i think it’s a lot messier to have everything crumbled up in fewer models, instead separation is good for organizing ur code, who cares about a few extra files, for rendering fields, i personally like to use react on the frontend , it’s very easy to change select options based on input or previous selected options with state management, last u will need to make logical form validation in ur view to save and organize fields in ur db tables writing some extra code is not bad
Rajjix
because at some some point u will need to edit and improve or change something in ur code, it’s a lot easier to read and edit a couple of extra files simple codes files, than to comprehend 1 small very complexed code
Rajjix
that’s how it’s used actually
Rajjix
it’s javascript inside ur body tag
Anders (izzno / gooood) 🇳🇴
I'll have a look at that.
Anders (izzno / gooood) 🇳🇴
Any recommendations for learning (from scratch, don't know Java or js)
Rajjix
it’s just js no java needed, look on youtube for mosh, he has two courses one for react and one for javascript about 4 hours both, that was my start point, then ur on your own experimenting stuff
Rajjix
i also can help if needed
Anders (izzno / gooood) 🇳🇴
Thanks, I'll have a look 👍
Rajjix
bear in mind that u’re not obligated to use react solely on ur front end, u can import cdn in ur header and write react components in ur body, if you don’t want to completely separate the front end for only react. react documentation has a few ways on doing that
R
But you want to use react in the admin site?? Additionally, not an expert on js (actually I fking hate it) and don’t want to create a debate like vim vs nano, but I think vue is easier and needs less js knowledge than react
Rajjix
But you want to use react in the admin site?? Additionally, not an expert on js (actually I fking hate it) and don’t want to create a debate like vim vs nano, but I think vue is easier and needs less js knowledge than react
With react router u can link ur django admin panel to a specific route, yes i’ve heard vue is easier to use, it’s on my to learn list. But for now i feel very comfortable using react, no doubt it was confusing at start as any other framework or new material we try to learn.
Manish
social = SocialLink.objects.all() home = Home.objects.all() contact = Contact.objects.all()
Manish
i always need to execute these query on every view. Any way to make this execute only one time and i can use this on every page
Rajjix
save it in a list
Manish
save it in a list
then how to pass it in other view
Rajjix
optimal optional is to use redis as it’s like a database in ur memory, but i don’t think u need it now