Allan
The models are entries that each one should belong to a user. Let's say for example a Journal: each entry in the journal table should belong and accessed by only the owner. But this user thing wasn't planned and now I'm trying to fix this. I'm good at python, but I am not experienced in Django.
Allan
The first approach is to have a different database for each user. But there are some models (tables) that are general and not user specific, and after the user log in he need to use there (ie. I cannot run a different instance of Django for each user). This one I believe is pretty impractical with Django.
Allan
The other one is using an internal user field. So, as all models that are user specific user a Custom Abstract Base model to save creation and update times, and no one else uses it, It’s already on the way.
Allan
I override the save function on this Base class to always take the user (with a few hacks) and save it. And created a custom manager that filter the results for the ones the user owns.
I’m having a lot of trouble with this approach, I don't now if it's the best one.
Allan
What I would like to now is if this is the best approach, if there is any realistic possible approach besides those, what would be the better ones. Or even if I’m missing something like a django module that makes this, or anything.
Elizaveta
Hey, can anybody help please. I'm making models for my db. The First model is dish, it has name and price. And the second one is order, it should have 4 fields, two of which are 'total price' and 'consists of'. These fields are foreign keys from dish and may have any number of elements. How do i properly bound them in model?
Anonymous
I don't understand what you're trying to say
Anonymous
Website
Anonymous
?
Anonymous
http://graphql.org/learn/
Anonymous
It's is python version GraphQL
Elizaveta
I don't know how to do it
Elizaveta
The first field will have several values from another class. Is it:
value = models.ForeignKey('another class')
?
Elizaveta
But what if i want to store several values there? How i can do it?
Abhi
@Formalin extend the user model
Abhi
and make a one-to-one relationship with that extended user model
Elizaveta
Could you please show me an example?
Abhi
Okay wait
Abhi
https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html
Abhi
hope it help
Anonymous
inchidi
inchidi
so for every order you will store the dishes ordered, and how many is it. your views gonna do the math and you get the bills
Django Bot
>> Blogs
- Is Django the Right Fit for your Project?
Elizaveta
Anonymous
Anonymous
inchidi
Anonymous
But it have disadvantage that the frontend man have to communicate many time with backend man
inchidi
Anonymous
Unless you're full stuck
inchidi
i see, sounds like its gonna give flexibility for front end
Anonymous
Then frontend man pick what his wanted
Anonymous
You are welcome
Anonymous
Anonymous
Frontend developer can do whatever he can
Anonymous
Then back end developer ask him to change something
Anonymous
Agree with you
Anonymous
I thought he said opposite
Anonymous
Anyway
Anonymous
If Meaning same, no problem
Anonymous
Allan
The main problem is always filtering the query to just return the records that the user own. I extended the default Manager for this custom class, so the get_queryset always filter by the current user. It works fine on the shell, and on the views too I think.
Allan
But when I start the server it crashes because the ModelForm does a query when creating the class or instance at the initialization. Because it doesn't pass any user, and there is no user related to that query, I can't handle it.
Allan
Because there's no sense for me making queries on a model without even a user been logged in.
Allan
It also breaks many others stuffs that I have no idea why.
Allan
That's why I'm questioning about if this is the right approach, because I would have to know in detail all Django source to know the answer for this, or how to fix stuffs.
Django Bot
>> Blogs
- Two Scoops of Django Birthday Giveaway
Anonymous
Congratulation....got 90 members....👍
Anonymous
Anybody here wanna do for a gamble game website ?
Lapanit ☃️
How much are you paying?
Anonymous
Val
Allan
Allan
My problem now is that the ModelForm populate the ForeginFields at startup, and then doesn't update (make the query again), so it only got results for this fileds of the first user...
inchidi
inchidi
inchidi
if user will not input that fields, you can just exclude it for that ModelForm
inchidi
then your views pass the request.user
Django Bot
>> Jobs
- 2017 - 2018 Fall & Winter Django Web Developer Internship
>> Blogs
- Find static files defined in django-pipeline but not found
Lapanit ☃️
/warn ad
Group Butler
Hacker Linux™ has been warned (1/3)
Val
hello does any one have an article or book on recursion in python
Anonymous
Book on recursion?
Anonymous
That's too much
Val
i found something thanks
Val
class Test(unittest.TestCase):
def test_should_say_hello(self):
self.assertEqual(say_hello("NAME"), "Hello, NAME!")
Val
pls can someone explain this codes to me?
Val
For this practice challenge, write a simple greeter function.
If it is passed in a name NAME, return 'Hello, NAME!.
If it is called without a name, return 'Hello there!.
Val
class Test(unittest.TestCase):
def test_should_say_hello(self):
self.assertEqual(say_hello("Qualified"), "Hello, Qualified!")
Val
def say_hello(name):