Anders (izzno / gooood) 🇳🇴
I think I have a way to refraze the big question I am still trying to solve: I have a model ProductItem and a model Type, the problem I have is different types need different fields. If I were to create a different model for each "type" I have there would be about 100+ models. So i tried to figure out how to create dynamic fields, theres a couple of options out there but none fit the bill excatly. I need the Type model to have a set of defaults depending on what Type it is. So I am thinking, is it maybe better to have a default field in json/dict or commaseperated list with key=value and use this type as a template to transfer the "attributes" to a simuler field in ProductItem
Anders (izzno / gooood) 🇳🇴
The main purpose is to perform tests as one ads productitems to "basket" to make sure they fit together
Anders (izzno / gooood) 🇳🇴
and again, any suggestion of a structure is apriciated.
Gautham
https://github.com/satwikkansal/wtfpython/blob/master/README.md
Anders (izzno / gooood) 🇳🇴
https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#hstorefield I think I finally got it...
Anders (izzno / gooood) 🇳🇴
or a json field
Феруза Норкулова Узи врач
Hi guys how to get free udemy courses
cj
Hi guys how to get free udemy courses
You can check yourself if udemy is giving free courses of your interest
Bekzod
I've already checked. But I want to get "traversy media django from dev to deploy" courses
Rajjix
it’s really expensive to buy a course for 9.99$ right? you would pay that much for a couple of beers or a taxi fare, but not for a 30 hour course? people really spend hard work on them the least you can do is buy them a beer 🍺
Anonymous
Also, someone tagged me two times
Anonymous
Who was it
Anders (izzno / gooood) 🇳🇴
Anonymous
Analysing your problem properly
Anonymous
And creating a good model of it
Anonymous
If you haven't I'll suggest you to study bit about DBMS
Anonymous
There is one course on Stanford lagunita
Anders (izzno / gooood) 🇳🇴
I don't have time for that now.
Anonymous
🤷‍♂
Anders (izzno / gooood) 🇳🇴
Do you have the answer?
Anonymous
I see three relations here
Anders (izzno / gooood) 🇳🇴
Don't look at that, it's poorly explained
Anonymous
I'll suggest to have foreign keys and don't fall for that dictionary stuff
Anonymous
Otherwise at sometime you'll somehow you yourself will have to create a schema and it will go all round
Anders (izzno / gooood) 🇳🇴
I agree, the problem is the different types and data I need will be different pr type.
Anonymous
Why?
Anders (izzno / gooood) 🇳🇴
I have a 6hout flight tomorrow, I'll read about dbms
Anonymous
Maybe you are creating a poor model
Anonymous
Maybe..
Anders (izzno / gooood) 🇳🇴
Yes
Anders (izzno / gooood) 🇳🇴
Not maybe, probably
Anders (izzno / gooood) 🇳🇴
Let's say I have a produkt that's a camera
Anonymous
I have a 6hout flight tomorrow, I'll read about dbms
The one on Stanford lagunita are lectures. Probably 4-5 hours length
Anders (izzno / gooood) 🇳🇴
It has a type model camera (foreign key)
Anders (izzno / gooood) 🇳🇴
I need this to have x inputs x outputs
Anders (izzno / gooood) 🇳🇴
Then I have a product sensor
黒の戦士
Hello everyone!
黒の戦士
Can someone help me with DjangoGap?
黒の戦士
I need course plz
Anders (izzno / gooood) 🇳🇴
It has a type, which need x other values
Anders (izzno / gooood) 🇳🇴
Each type needs attributes, but they can be different.
Anders (izzno / gooood) 🇳🇴
I can make an attribute model as well, but the problem keeps comming back to the fields being static, unless I just make a key/value model as attribute then add objects and link them one to one.
Anonymous
Can I get a real exam? Like the one from your real problem.
Anders (izzno / gooood) 🇳🇴
Sure a second
Anders (izzno / gooood) 🇳🇴
https://pastebin.com/8ry7f6Dt
Anders (izzno / gooood) 🇳🇴
As a test I added the attributes the "product" needs in the ProductItem model. The Key job of the attributes in to perform tests when somone is using the pricingmodel (later) to make sure that x amount of inputs have the corresponding equipment with inputs.
Anders (izzno / gooood) 🇳🇴
There can be X amounts of product types having X amounts of attributes depending on Type. The main goal is for me not to have to do a migration if say someone enters a produkt that need a new attribute like say "analysis=yes"
Anders (izzno / gooood) 🇳🇴
My problem is I am not experianced with DB (like you commented), so I will read your suggestion. It might give me a better idea.
Anders (izzno / gooood) 🇳🇴
All I see now is I can solve this in the "frontend" and store it in a json.
Anders (izzno / gooood) 🇳🇴
But I dont want to be doing "bad" practice.
Anders (izzno / gooood) 🇳🇴
EOL
Anders (izzno / gooood) 🇳🇴
No
Anders (izzno / gooood) 🇳🇴
Only if they are unknown
Anders (izzno / gooood) 🇳🇴
A cirtain type can have different propperties
Anonymous
Do you know exactly how many types you have?
Anders (izzno / gooood) 🇳🇴
Never
Anders (izzno / gooood) 🇳🇴
I will pinpoint the problem 2 sec
Anders (izzno / gooood) 🇳🇴
Say you have a type "Bullet Cam" This type has fields input/output. Then they get a Bullet Cam tha also has a Wiper. (boolean or what ever). I cant have a static type model, unless i need a model for every type.
Anders (izzno / gooood) 🇳🇴
i "can" add all the possible attributes in to an Attribut model and only show the relevant based on Type but again if a new atribute shows up i will have to add a field and do a migration.
Anders (izzno / gooood) 🇳🇴
Not self sustanable
Anders (izzno / gooood) 🇳🇴
an array of attributes stored in another model and handled by the frontend could be.
Anders (izzno / gooood) 🇳🇴
But it would not be "readable" code.... at all...
Anonymous
Well...m
Anonymous
For you now you can try JSON
Anonymous
Until a good model is yielded
Anonymous
For you now you can try JSON
The way you suggested :p
Anders (izzno / gooood) 🇳🇴
I will do the read tommorow ;)
Anders (izzno / gooood) 🇳🇴
And bring some paper and a pen, who knows, maybe magic happens.
George
Hi, im looking at my querys and i can call a a=Model.objects.get(pk='1') and a: a=FailureType.objects.get(pk='1') but not a: a=FailureType.objects.get(pk='') in which i get a casting error. How to handle this situation correctly?
Rajjix
if the query is empty you mean , or if he searches for an invalid pk? pk is an int btw u don’t have to use the ‘’, but it works both ways
Rajjix
u can just add a custom query method or even override the existing get query method and replace and add a try except, or better: def <query_name>(self, itempk): query=model.objects.get(pk=itempk) if query.count() == 1 return query.first() return None
Deleted Account
Hi everyone. I use generics.listCreateAPIView and it looks good when I run in local host. But when I run in postman it says it needs authorized token. So I search the internet. It introduces rest-auth using with User model. I have a model name people, storing user information. Do I need generate a token for every user?
Akshay
yes
Akshay
If you won't generate token for every user, how would you differentiate users?
Deleted Account
but i am not using the Superuser model, i still can generate a token with rest-auth? sorry for my stupid question.