These are chat archives for django/django

26th
Feb 2016
agent3bood
@agent3bood
Feb 26 2016 10:35
@megapctr how about creating field and make it store the value of count, we can update hourly or even on every new post added
count = MyModule.objects.count()
Filip Figiel
@megapctr
Feb 26 2016 10:37
@agent3bood yes, but why do you need to store it?
agent3bood
@agent3bood
Feb 26 2016 10:39
Isnt the count function consuming resorces? Maby call the cound from db will be faster.
Filip Figiel
@megapctr
Feb 26 2016 10:40
queryset.count() works on the databse level
kdelinx
@kdelinx
Feb 26 2016 10:41
@megapctr will be better: Model.objects.annotate(qs=Count('releted_name__field'))
Dmitry Grebenshchikov
@grebenshchikov
Feb 26 2016 10:41
@kdelinx it’s true!
Filip Figiel
@megapctr
Feb 26 2016 10:42
nice
Dmitry Grebenshchikov
@grebenshchikov
Feb 26 2016 11:28
Guys! how to fix this bug in pool PicklingError: Can't pickle <type 'thread.lock'>: attribute lookup thread.lock failed
It’s celery task
2xS
@i2xS
Feb 26 2016 11:34
@itcrab look at the awesome app for your case https://github.com/django-denorm/django-denorm. it works on database triggers
and has daemon to update counts in regular intervals
Yanik Koval
@yanikkoval
Feb 26 2016 12:56
Filip Figiel
@megapctr
Feb 26 2016 13:07
@yanik5: pass res['Body'] instead of res['Body'].read()
StreamingHttpResponse expects a file-like object, not the content itself
wait, I'm wrong
docs say: "It should be given an iterator that yields strings as content."
2xS
@i2xS
Feb 26 2016 15:04

need some tiny help
i have 2 models, and one is related with other by ForeignKey, for example:

class Bar(model):
   ...

class Foo(Model):
    barbar = ForeignKey(Bar, related_name='foos')

trivial

So how can i get the name of the field ('barbar' in example) that contains ForeignKey to Bar in Foo model, if i have only bar object and relatedname in sting 'foos' ? Any help appreciated :)

Filip Figiel
@megapctr
Feb 26 2016 15:09
@i2xS: getattr(bar, related_name)
uh wait, you want to get the string 'barbar'
2xS
@i2xS
Feb 26 2016 15:10
@megapctr it will give me RelatedManager
Filip Figiel
@megapctr
Feb 26 2016 15:10
in that case, I'd fiddle with bar._meta.get_field().model._meta....
2xS
@i2xS
Feb 26 2016 15:17
uhh. bar_ob._meta.get_field_by_name('foos')[0].field.name did the trick
now the same with GenericRelations...
Filip Figiel
@megapctr
Feb 26 2016 15:44
yeah, you're probably doing something in a very wrong way
2xS
@i2xS
Feb 26 2016 15:53
if so, which way will you suggest to copy one model object and automatically copy all of it's related objects, replacing theirs ForeignKeys to new object. recursively.
kdelinx
@kdelinx
Feb 26 2016 15:54
@i2xS nice way