postgres for example has quite a lot of dedicated types.
UncleVasya has quit
jaykay1
yeah... maybe you're right
jessamynsmith
jaykay1: it's simply not designed for production use, even for small sites
jobelenus has quit
adsworth joined the channel
lolidunno has quit
safwan joined the channel
lomex joined the channel
codermato has quit
lobo_d_b has quit
Catatronic has quit
Meteoroid joined the channel
Meteoroid
how can I get the static_url path in my python function?
just import settings and do waht?
cmgurba joined the channel
newdimension joined the channel
Ch3ck_ joined the channel
zeus1 has quit
fikka joined the channel
geekodour08 joined the channel
csotelo_ has quit
cmgurba has quit
cmgurba joined the channel
ramHero joined the channel
adsworth has quit
cmgurba has quit
adsworth joined the channel
crCr62U0 has quit
crCr62U0 joined the channel
kapil___ has quit
graphene has quit
newdimension
I'm creating a notification system for my project. I need a module to track which users get notified for each object. There's two ways I can store the relationships (1) One Participants model that uses generic relations to link to the different object types. (2) An object specific participants model e.g. TaskParticipants, ContractParticipants etc... The reason I'm considering (2) is that I've read that one needs to think of
their db outlasting the app. And if I rely too much on geeric relations I'm obscuring the relations at the db level
graphene joined the channel
Any thoughts?
fronchetti has quit
audioburn has quit
jessamynsmith has quit
audioburn joined the channel
jessamynsmith joined the channel
fission6 has quit
mnemonicj has quit
jessamynsmith has quit
mnemonicj joined the channel
jaykay1 has quit
greatgatsby
maybe just me, but any time I'm starting to categorize things like that, I think I'd have an ObjectCategory model that lists each object category, and then each participant (user model?) would simply have a foreign key to an object category. This might be way off base since I don't think I fully understand your question.
kris7ian joined the channel
then doing things like get all participants, get all participants that belong to these categories, etc, is easy
Catatronic joined the channel
LiftLeft has quit
ticketbot has quit
ticketbot joined the channel
newdimension has quit
newdimension joined the channel
kris7ian
I am regularly updating my database with a dataset from a foreign api (using celery beat). I always get the last 10 occurrences to be sure that my db doesn’t have holes, even though only the last occurence should theoretically be needed to update the db. Until now I didn’t use django’s ORM but I want to switch to djangos ORM now for various reasons. I have set a uniqe=True on the timestamp, now I guess I will get errors when
updating, since only the last of the 10 ocurrences is unique. How do I prevent this? With get_or_create?
nix64bit joined the channel
LiftLeft joined the channel
Meteoroid
oh no there is no weekend crew in this irc :(
I just need some help figuring out how I can use the static_url as a variable
what do i import?
how do i set the variable?
rpkilby has quit
newdimension
greatgatsby: No I think you're on to something. A through table can be used instead of a generic relationship
Meteoroid: There is, but due to different timezones you get most of the people later in the day
pere has quit
newdimension_ joined the channel
Meteoroid
I guess there is also the fact that most people work Django on payed hours at their place of work right?
audioburn has quit
newdimension has quit
newdimension_ is now known as newdimension
newdimension
Not really, people answer during the workday as well
rpkilby joined the channel
The only day I feel it's day is Sunday
*it's dead
Meteoroid: What are you trying to do with static_url?
Meteoroid
returning a path for an <img src=¨¨ /> outside of a template
Debnet has quit
before you ask why I do this outside a template, because I am customizing a oembed reply, which is already in html form because that is how an oembed response works.
rpkilby has quit
newdimension
from django.conf import settings STATIC_URL = getattr(settings, "STATIC_URL, None)
Then you can build the full url: domain + static_url + filename
I haven't done this before, so this might not be the most efficient
Meteoroid
thanks, would not have expected I needed to get the attribute like that. Learned a new trick, although I know not to do that often.
gargantua
I understand that you can check if a user has the permission to change models in general with user.has_perm("foo.change_bar") but how do you check if they can change a /specific/ bar
Meteoroid
dont need the domain, its a path on the same site
newdimension
You can get the domain from sites framework FYI. (it's part of Django)
gargantua
for example, if the model represented posts, and you wanna make sure the user can only change his own posts
Meteoroid
or do i need the domain? :0 I need to check that
csotelo joined the channel
two_tired2 joined the channel
newdimension
gargantua: There are two kinds of permissions: (1) Model level: A user can create Tasks objects. (2) Object level: A user can edit this specific task
BSL joined the channel
Django comes with (1) only. You can use django-guardian for (2)
However, make sure you read the docs and figure out if you can implement without django-guardian. There's a few methods to implement stuff like "edit own comments" and such
rpkilby joined the channel
Meteoroid
wait a second. I could just from django.conf import settings settings.STATIC_URL
newdimension
that works as well
eht_ has quit
rpkilby has quit
gargantua
newdimension: well I am thinking just make a ForeignKey with user id in the Post model and check against that, not using permissions at all
newdimension
That's what object level permissions are. You might as well use django-guardian as they provide you with convenient methods
But a good amount time you can get away without db level checks. There's a method "must pass test" or something along those lines that can be done to do logically tests. request.user == comment.author
*logical tests
The advantage of that is that you don't have to worry about managing a new model
gargantua
I mean comment.author must come from the db
Donitzo has quit
newdimension
for sure. I phrased it wrong, I just mean additional DB lookup. Anyway it's unlikely to affect performance. I just like to keep things I manage to a minimum
kapil___ joined the channel
knbk
it's pretty standard to just use .filter(author=request.user) in your view
Donitzo joined the channel
csotelo joined the channel
csotelo has quit
ramHero has quit
Xard has quit
BSL has quit
graphene joined the channel
kiloreux joined the channel
adsworth has quit
rpkilby joined the channel
newdimension
If I want to compare date (without time) should I be using python's datetime or django's timezone?
gyia joined the channel
eb0t_
hey i have some main clients on the database and there is a model for the client...i then add a number of contacts records which are based at the client...
this means that every contact has a foreign key of main client
and you cannot add a contact until you have added a main client
the thing is when i create the contact ...i need to make sure i attach it to the right client
eg if the main client was microsoft... and i had a contact record for bill gates at microsoft
how would i make sure that the foreign key picks up the main microsoft client on the entry form
i mean ...a user may type in microsft ltd...another user may type in Microsoft , and another user may try and register bill as working at Microsoft corp
in reality i just want to make sure i end up with the right foreign key
how is this achieved.
becasue to the database there is a difference between microsoft and Microsoft and Micro soft
or barclays and barclays bank and Barclays
newdimension
eb0t_: Don't let users decide the name
Give them a dropdown
eb0t_
how would i give them a dropdown
i was looking into something called initialise
but that autopopulates other fields
newdimension
Create two models (1) Company (2) Contact. Add a foreign key in Contact that points to Company. Modelform will create a dropdown for you in ContactForm
eb0t_
you see in reality if the user types in bar...i want a list to drop down of every instance containing bar case insensitive for companies
ah wow ..you mean to say that Modelform will automatically do this for me
surely not
newdimension
That's an additional step ontop of what I suggested which is filtering on the frontend
it will. And you really need to read the docs
eb0t_
im constantly reading the docs ..i just didnt find this
newdimension
Reread modelforms. You've missed a bit.
I missed a lot when I frist read them, but everytime I reread I learned more
eb0t_
ok thanks newdimension, if this can be done automatically...i have been witholding creating the second record until i sorted it out
maybe i should have jsut done it and seen what happened.