Hi everyone! I'm using django s3-direct to upload files from django to aws s3 service. Works great. Now I would like to be able to delete the file from django AND aws S3. Someone already tried that ?
sarp has quit
pathrocle joined the channel
empedokles78
I'm using an m2m intermediary model to state membership like information. companies can be member of multiple associations and associations can have many members. What does on_delete mean in "person = models.ForeignKey(Person, on_delete=models.CASCADE)" ?
fleetfox
Anyone knows if there is NaiveDateTime? I'm USE_TZ=True, but some of my fields are naive for legacy reasons
empedokles78: if person is removed it will delte your membership
kezabelle
fleetfox: I don't think there is, but you could subclass DateTimeField and change the to_python etc?
empedokles78
fleetfox, that might be unwanted (it could be transfered to another company), are there other options?
ovtrn joined the channel
sec^nd has quit
linurandy_ has quit
sec^nd joined the channel
morenoh149 joined the channel
fission6
if i have two model managers on a model, how can i chain calls across the two managers, for instance Place.recommendations.for_user(user).live() where live is defined in the default "objects" manager
jerojasro has quit
fleetfox
kezabelle: i think it's more involed
Ahuj has quit
empedokles78: use PROTECT, and handle ProtectedError. Or if you can always resolve instance it should be transfered to use SET
empedokles78
fleetfox, That's over my head for now, so I should set it to "on_delete=models.PROTECT" currently?
PrashantJ joined the channel
marlinc joined the channel
vamiry has quit
Will "date_left = models.DateField(null=True)" do for a membership, which not yet has ended?
felixx has quit
fikka joined the channel
pathrocle has quit
pathrocle joined the channel
imack joined the channel
Silvering has quit
fleetfox
yes
bakirelived has quit
Hawkerz joined the channel
arielfe1984
guys i have a question
Knyght
ok allow me to read your mind to find out what it is
you want to hire me and give me the big bucks?
kl4us joined the channel
sef joined the channel
arielfe1984
lol
not really
Knyght
I guess you'd better just type it out then
arielfe1984
im using a dictionary that holds the format for a query that goes to elastic search. The problem is that in one of the nested dictionaries inside that dictionary i need to have duplicate keys - thats the way the elastic query works... how can i solve it?
Knyght
I'm pretty sure elasticsearch doesn't require a dictionary with duplicate keys, since that's impossible. You're using the python lib I assume?
linuxvorpal has quit
jas02 joined the channel
arielfe1984
yes
fission6
does anyone here use multiple managers on a model?
Knyght
fission6: probably
arielfe1984
my bad - after your comment i double checked and you are right - it is a lost of dicts which both have the same key
Knyght
arielfe1984: so you're using the querystring format?
arielfe1984
fission6 - yeah
fission6
Knyght arielfe1984
if i have two model managers on a model, how can i chain calls across the two managers, for instance Place.recommendations.for_user(user).live() where live is defined in the default "objects" manager
Knyght
yeah that's what I was about to get it
at*
arielfe1984
Knyght - thanks a lot :)
Knyght
fission6: don't think you can, you should instead use custom QuerySets rather than custom Managers
fission6
Knyght how would that work
would it be typical subclassing
like how would i be able to mix chained called
Knyght
well your .live() is a QuerySet, right?
bakirelived joined the channel
fission6
from an OOO subclass standpoint it would be a method on a QuerySet
Knyght
or rather a qs method
yeah
fission6
sure
and it would return a an instance of QuerySet
Knyght
hmm one moment I'm trying to use brain
kezabelle
you probably wouldn't attempt to chain calls between them, but to have them share a base class.
Knyght
why not - what kezabelle said
pathrocle has quit
fission6
thats kind of lame but seems like the only way
Knyght
have a base manager that has live() and then your other manager uses it as a base class
sorry that has for_user
you know what I mean
pathrocle joined the channel
fission6
so like have a base QuerySet class with "core" logic and then inherit that into other managers
for more buisness logic type "things"
kezabelle
technically there'd be managers, but I'd just do it with .as_manager() and have MyQuerySet subclasses.
felixx joined the channel
fission6
ya
fikka has quit
Itkovian joined the channel
kezabelle Knyght do you two have. guiding philosophies on what should even be manager methods/queryset methods, ive heard people say you should not pass in parameters to them, and if you do to use more of a services layer that deals with parameters or with Two Models to get to some logic
vamiry joined the channel
Knyght
I use custom QuerySets quite liberally
I try not to put too much in them other than db stuff, that's my main thing really, 'cause it feels like hiding code and sometimes it can be a bit unclear where it's coming from
jas02 has quit
jas02 joined the channel
I dunno, it's quite simple to me - if there's some query I need to do more than once, it goes in a custom queryset
fission6
do you have methods that do not return a queryset but perform some DB operations to get to a result
Knyght
sure - delete() is builtin an example of that
_heena_py_ has quit
I think those are terminal querysets, stuff like delete and aggregate
PrashantJ has quit
gugah has quit
kezabelle
indeed. count, aggregate, update, delete etc.
finster
hello there. using django 1.11. i've got a jinja2 template that has a comment string in it, like <!-- mycomment -->. I'd like to check for that string via a test: https://dpaste.de/yKsu
fission6
Knyght i find myself often doing this pattern, curious what your thoughts are I have a method on a customer Queryset Product.objects.for_company(company), then I have a model method on Company def get_products(self): return Product.objects.for_company(self) - so that i can do something like company.get_products() - how do you feel about this
finster
however, the test fails. where am i going wrong?
jas02 has quit
s/mycomment/booklist template/
bakirelived has quit
bakirelived joined the channel
fission6
kezabelle feel free to weigh in too ^
pathrocle has quit
empedokles78
Do I need to specify a field in the intermediary model which is set to null in the shell?
pathrocle joined the channel
Knyght
fission6: dunno - I probably wouldn't do it myself but I don't see much harm in it - maybe you miss out on some optimisation but haven't thought about it very hard
kezabelle
fission6: I've done similar, though I'd use the reverse relation rather than Product.objects ...
mostly because then I can (ab)use any prefetch cache that exists at the instance call time.
fission6
kezabelle i do the reverse relationship when it makes sense
kezabelle
avoiding littering .filter(...) or .all() (or {{ .all }}) around the place can be a valuable thing because then you can keep the existing API and wholly change the underlying code.
finster
are HTML comments ignored by assertIn function calls?
notemerson has quit
kezabelle
plus you're making moves towards encapsulating data in one source of truth
fission6
kezabelle yea makes sense
just never knew if i was violating something through that pattern
Knyght
finster: have you tried using assertContains instead
also the obvious things of showing us your template and making sure the comment actually ends up on the page at that url
k0mpa has quit
sec^nd has quit
sec^nd joined the channel
finster
Knyght: okay, thanks for the link. yes, i verified that the comment is visible when using a usual browser. in the test suite, however, it seems that the included template file cannot be found. still investigating