|
I just skimmed your post, because I've been doing that a lot lately for some reason, and it's been awhile since I've done something requiring celery, but... You've got to get the task id from where you instantiate it to where you want to query the task state. django-celery doesn't really have any mechanism to tie tasks or task results to a specific user. So yes, you need to store task ids belonging to users in some manner. Then, when the user uses a view that needs the task results or status, you can do this: http://docs.celeryproject.org/en/latest/faq.html#how-do-i-get-the-result-of-a-task-if-i-have-the-id-that-points-there
|
# ? Feb 26, 2016 18:02 |
|
|
# ? May 16, 2024 16:59 |
|
Thermopyle posted:Anybody in here tried to set up and use any of the various solutions out there for Websockets + Django? How'd it go? Have you looked at Pusher at all? Their free tier includes 200k messages a day. We use it + DRF at work to do some data streaming with Kinesis, and it's pretty great. Also found this on their site: https://blog.pusher.com/django-pusherable/
|
# ? Feb 26, 2016 18:26 |
|
Working on my first Django project, after years of C# and ASP.NET, and I've got two questions that feel stupid. 1. Where do I put the program state? Working in ASP.NET, it was easy enough to add a simple C# object to handle data structures that didn't really belong in the database, but I can't find anything in Django docs on how to do that. Specifically, I need some place to put the Primary Data Structures listed on that README; order of jobs to be done, the calculated average time each person spends in the queue, and how much money is in the machine. The sort of data that does belong in the backend model, but not in the existing model classes, and which will be referenced enough places that I'm hesitant to just put it in the views. I'm considering using this dude's singleton model, but want a second opinion and/or other advice. 2. I think I just found the answer, but how do I attach additional data to the authentication user model? In that project, I need a Customer class with a time value and some other info, and I would like to connect that to the authentication system and their User class, if only to avoid having an "And which customer are you again?" field on some of the forms. The linked section is probably the way to do it, but not 100% sure.
|
# ? Feb 29, 2016 22:22 |
Yeah, that's pretty much what you do. An extension model with a OneToOneField that extends the base User class, and then you'll have those fields whenever you have a request.user object.
|
|
# ? Mar 1, 2016 18:10 |
|
https://www.youtube.com/watch?v=EP6l1SZwF7Q I made a short 15m video explaining a recent django CVE yall might like Any and all feedback is really appreciated!
|
# ? Mar 2, 2016 00:49 |
|
Sharktopus posted:https://www.youtube.com/watch?v=EP6l1SZwF7Q I didn't watch it all because I'm a child of the internet, but the first half was informative! (I also find myself searching a page of code on github not infrequently...try searching "def get_format" to bypass all the spurious results you get when you search for "get_format")
|
# ? Mar 2, 2016 01:17 |
|
Eleeleth posted:This is what I did, it works a lot better than trying to integrate websockets into django, in my limited experience wrestling with things like swampdragon. what problems have you been having with swampdragon? I'm using it for my current project, and I like it quite a lot so far.
|
# ? Mar 3, 2016 12:18 |
|
What would be a good way to manage a collection of temporary session hashes? I've started working on a goon auth server that will require goons to post an auth hash to their profile. What I want to do, though, is create an eligible hash/username combo (defined in a Model) around only for a short period of a time, a few minutes, before it gets cleared from the database. Is there a way to automate the nuking of the record after X minutes? Would it be easier to just make a cronjob that calls a python script that Model.objects.filter()s anything later than time + X minutes and deletes them? Edit: the correct answer is a cronjob and a custom management command: https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/ IAmKale fucked around with this message at 08:40 on Mar 5, 2016 |
# ? Mar 5, 2016 05:25 |
|
A cron job that runs every few minutes is probably overkill. Don't use a database, use a caching server with an expiration set for that. Memcache or redis are great. Alternatively, in your model have an expiration field and alter the default query set so it only ever gets unexpired ones. Something like: http://stackoverflow.com/questions/2494501/modify-default-queryset-in-django Then you can have a daily or weekly job that cleans up.
|
# ? Mar 5, 2016 14:38 |
|
Yeah, I wouldn't use the database. That's being said, I always first think of task queues like Python-RQ and Celery when I need to do Django stuff outside of the normal request-response cycle.
|
# ? Mar 5, 2016 15:08 |
|
Gounads posted:Don't use a database, use a caching server with an expiration set for that. Memcache or redis are great. Thermopyle posted:Yeah, I wouldn't use the database. Thanks for pointing me towards Redis, I've never used it before but it looks simple to use (it's basically in-memory JSON?) and I like the ability to set expirations on keys to have them disappear automatically. That should make it really easy to keep things tidy.
|
# ? Mar 5, 2016 17:25 |
|
Demonachizer posted:Do any of you know if there is a way to change the order than django does a clean() on form data? Essentially I have a form in the order I want and it validates email to come from a certain domain. I would like it to skip that validation if the user is from outside as a guest but the 'position' field is must lower in the form. When I do position = self.cleaned_data.get('position') it stores None to position. I have tested tossing position ahead of the email field and everything processes through just fine. Maybe I'm misunderstanding - you can validate form fields individually before they're validated with clean. It's especially useful when composing together form mixins. code:
WINNINGHARD fucked around with this message at 12:51 on Mar 6, 2016 |
# ? Mar 6, 2016 12:47 |
|
Back in 2006 between semesters at school, I wrote a web app for a small company. It's a LOB, standard parent-child table relationships (maybe 30 tables), simple log in/out system, written in Java for Tomcat using JSPs, database is MS Access (was a requirement, lol). The drat thing has been in production ever since, and is still ticking (though after moving to a new office, they're not sure which office computer is actually running the web server). The plan is to rewrite it in Django (I'm currently maintaining a half dozen Django sites, all using the latest 1.8 release). 1) Should I stick with 1.8 because LTS? 2) I need to write a one-time migration program to move data from Access to Postgres. In the old system the "id" primary key value matters, on some tables. For example, they use it as a reference number when printing (and later billing) service reports, so I need to keep this value around. If I want to continue using it as a pk, I need to somehow migrate the data to the target DB with a non-auto-incrementing pk, and then post-migration set it to auto-incrementing. Does that sound about right? At least I'm rewriting my own legacy system, rather than some other legacy system written by some other crazy person
|
# ? Mar 9, 2016 22:44 |
|
epalm posted:Back in 2006 between semesters at school, I wrote a web app for a small company. It's a LOB, standard parent-child table relationships (maybe 30 tables), simple log in/out system, written in Java for Tomcat using JSPs, database is MS Access (was a requirement, lol). The drat thing has been in production ever since, and is still ticking (though after moving to a new office, they're not sure which office computer is actually running the web server). 1.8 vs 1.9 is really up to you. You get an extra year of support out of 1.8, but miss out on whatever features of 1.9. You'll have to decide which you value more. Personally, I always use the latest but I'm a wild and crazy person. And yeah, I think you've got the data migration plan right.
|
# ? Mar 10, 2016 18:48 |
|
I'm having some weird problem with an update form using UpdateView. It seems to only happen on ManyToMany and ForeignKey fields. The ForeignKey fields never seem to be the right values (but on some items they are?), and the ManyToMany field seem to at least have all the right values but then it adds another one. Anyone have any idea what is going on here? Maybe I'm doing something really dumb. The two lines are the correct values dumped into context. E: It was something really dumb. For whatever reason I had this sitting in the page code:
hitze fucked around with this message at 03:10 on Mar 17, 2016 |
# ? Mar 16, 2016 22:59 |
|
I'm picking back up my attempt at writing a character generator for a tabletop roleplaying game, and one piece in particular is driving me up a wall. I'm trying to replicate this game's Merit system, which works thusly: - A Character can add Merits to their sheet - Each individual Merit has a different number of options for the level of said Merit - These options consist of 1, 2, 3, 4, 5. A large portion of Merits can be selected at levels 1 through 5, but all other combinations are also possible (2 or 3; 1, 2, or 3; etc.) There's other stuff like certain Merits needing others as prerequisites, but I'm not worried about that at this stage. This initial model structure is what's throwing me off - I'm not sure how to set this up such that when I pick a Merit, the level field will display only the options entered into the database as true. Since the Merits are their own thing, I have another model, CharacterMerit, that stores the Merit name and level for a given Character. I tried setting up the CharacterMerit and Merit models like so... code:
|
# ? Mar 21, 2016 19:36 |
|
I've just about thrown myself off a cliff trying to figure out some weird environmental issue I ran into. On my laptop, I added a small model, and then a M2M field on another model that uses the smaller one. Migrate, add some admin juice, and it's working great. Later, when I pull it to my main computer and try to run, Django just can't see the new model. It literally ignores the fact that it exists. Any imports result in 'ImportError: cannot import name MonsterTag', which Google says is a circular reference. The problem is, the same code works on my laptop just fine. What's extra weird is that if I run another makemigrations, it produces something despite there being no code changes since the last makemigrations. It produces:
It's like it can't even tell the goddamn model is in my code. I'm staring RIGHT at it. I reduced it down to just a single character field in case the custom fields (taggit, and ColorField) were not playing nice. I even went so far to run a diff on the entire project from both computers and they're identical. They connect to the same development DB. The virtual environments are identical as far as packages and version numbers.
|
# ? Mar 23, 2016 05:36 |
|
This is one of those step-back and check the basics situations. Make sure the file actually exists. Delete all .pyc files to make sure your not getting an old precompiled version Put a breakpoint in the model file, does it hit it? Make sure the app is listed in INSTALLED_APPS etc.
|
# ? Mar 23, 2016 12:26 |
|
It turned out to be the old .pyc! Thank you.
|
# ? Mar 23, 2016 16:45 |
I'm stuck with another lovely use case. We have objects, call them Books. We have Groups. We have Corrections which are usually specific to Groups, the one exception being Group 1. Everybody can see Group 1's corrections. We want to select all Books and get related corrections. If there are no corrections, we want to return just the Book with no extra values. If there are corrections by Group 1, we want to show Group 1's corrections. If there are corrections by Group n, we want to show only Group n's corrections to members of Group n (otherwise, show Group 1's corrections). We did this originally with some horrifying DB fuckery: sort by Group ID descending and do distinct on Correction.BookID before joining with Books. Our data team yelled at us, though, because this is really inefficient for 14 million books. I'm trying to think of another way to do it OR a way to redesign the tables to make this easier (other than denormalizing because then we get 10M * # groups). Is there a way to make IF x THEN x ELSE IF y THEN y ELSE z happen on the database level in the Django ORM? Hell, is there a way with SQL?
|
|
# ? Mar 24, 2016 21:51 |
|
I've been experimenting with Django Rest Framework lately, becoming more comfortable with it and experimenting with some of its third-party authentication packages. Somewhere along the way I became obsessed with the idea of getting the default settings.py file down to just the essentials. I wanted to see what parts of Django I could remove and still have Rest Framework work at full capacity. Right now I think I've found the absolute minimum number of Django-related apps that need to be included in INSTALLED_APPS, and I've nuked all the MIDDLEWARE_CLASSES and most of the default values set in TEMPLATES: Python code:
|
# ? Mar 25, 2016 05:32 |
|
It's hard to tell if you've gone too far without knowing the reason for your optimizing. Really major sites that use Django, you can bet everything in settings has earned its place there. If it's just a fun obsession, then that's fine. But it's the equivalent of those people who remove Aero or whatever theme Windows ships with because "that stuff is slowing my computer down "
|
# ? Mar 25, 2016 21:16 |
|
Hed posted:It's hard to tell if you've gone too far without knowing the reason for your optimizing. Really major sites that use Django, you can bet everything in settings has earned its place there. If it's just a fun obsession, then that's fine. But it's the equivalent of those people who remove Aero or whatever theme Windows ships with because "that stuff is slowing my computer down "
|
# ? Mar 25, 2016 22:27 |
|
I'm curious how things like sessions and CSRF work without a SECRET_KEY.
|
# ? Mar 25, 2016 23:41 |
|
porksmash posted:I'm curious how things like sessions and CSRF work without a SECRET_KEY.
|
# ? Mar 26, 2016 01:37 |
|
Some of the defaults for middleware handle sessions, the redirection to have slashes at the end (which is always a style question when running DRF), and some caching stuff that the client can pay attention to. I do think CSRF protection won't work without the middleware there injecting into the response and processing the requests. I'd be interested if all of that works as expected still. Still, it's kind of fun to see what can work.
|
# ? Mar 26, 2016 02:06 |
New question because I'm stupid, overwhelmed, and a bit rushed after a day of not being able to solve this simple problem: Here's my data model: code:
code:
code:
Also, I'm on 1.7 still. No Case/Where/When. EDIT: gently caress me running. What is this bullshit? code:
Jo fucked around with this message at 23:57 on Mar 29, 2016 |
|
# ? Mar 29, 2016 21:42 |
|
Does anyone know how to make date / time / datetime widgets work in Django forms? I've found nothing but broken addons and ancient admin hacks.
|
# ? Apr 16, 2016 15:10 |
Why does Django's migration generatecode:
|
|
# ? Apr 19, 2016 21:16 |
|
It looks like a lot of the links in the first post are broken/out of date. Which is fair enough since it's from 2008. It might be time to update it, maybe add stuff like The Djangogirls Tutorial http://tutorial.djangogirls.org/en Some Other Tutorial for experienced developers Cookiecutter Django https://github.com/pydanny/cookiecutter-django Awesome Django http://awesome-django.com/ Latest Djangocon videos https://www.youtube.com/playlist?list=PLE7tQUdRKcyaRCK5zIQFW-5XcPZOE-y9t Latest Djangocon eu videos https://opbeat.com/events/djangocon-eu-2016/ etc
|
# ? Apr 21, 2016 09:49 |
|
Mulozon Empuri posted:It looks like a lot of the links in the first post are broken/out of date. This link is broken missing a trailing slash
|
# ? Apr 21, 2016 14:21 |
|
Anyone else going to DjangoCon in July? I just bought my ticket. I'm mainly interested in hearing about channels and any kind of advice from high-traffic Django sites about scaling and caching.
|
# ? May 22, 2016 22:26 |
|
I'll be there!
|
# ? May 22, 2016 23:36 |
|
For like 4 years I'm always like "I've got to remember to go to DjangoCon next year." Then I'm always surprised when I read somewhere that DjangoCon is coming up shortly and I've already got plans.
|
# ? May 23, 2016 16:40 |
|
How widespread is cookiecutter-django? I came across it over the weekend and I really like it. It was also my first foray into using docker and docker-compose, which is neat. My major gripe is that running it on linux means running it via he root user, which means that any files you generate with django's makemigrations or dumpdata are chown'ed by root by default and for the life of me I couldn't find a neat solution to that other than chown'ing them back after I run the command. How does that transfer over to production though?
|
# ? May 24, 2016 11:55 |
|
I haven't used it, but I have heard of it several times. I can't imagine why you'd have to run it as root. I mean, sure, run the docker daemon as root, but I *think* everything else should work in user space?
|
# ? May 24, 2016 13:26 |
|
Gounads posted:I haven't used it, but I have heard of it several times. I can't imagine why you'd have to run it as root. I mean, sure, run the docker daemon as root, but I *think* everything else should work in user space? Yeah I'm not sure either, on the docker-compose django docs it just says: quote:If you are running Docker on Linux, the files django-admin created are owned by root. This happens because the container runs as the root user. Change the ownership of the the new files. Which isn't particularly helpful. I made a stack overflow post here about this but no replies yet. I think I've managed to confuse myself and everyone else. It just seems like this would be such a common issue to come across that I'm amazed that noone else has had a similar problem.
|
# ? May 24, 2016 16:24 |
|
Celery question! I'm working on a legacy app that has all of its tasks (there are many) in their own named queue. I just set up the quickstart guide's auto task discovery mechanism, but my issue is that they don't seem to run unless I specify -Q queue_name for each of the tasks that I am testing in the celery worker command. Is there some way to autofire queues that I don't know about? I thought CELERY_CREATE_MISSING_QUEUES = True would do it (True is the default but I tried anyway...) but it doesn't seem to do the thing.
|
# ? Jul 15, 2016 15:19 |
|
Anyone at or coming to DjangoCon US this week? If so, say 'hi'. Look for a guy with a big beard and a bright green "organizer" ribbon.
|
# ? Jul 17, 2016 20:50 |
|
|
# ? May 16, 2024 16:59 |
|
MonkeyMaker posted:Anyone at or coming to DjangoCon US this week? If so, say 'hi'. Look for a guy with a big beard and a bright green "organizer" ribbon. Yup, I will be there. I will say hello to all bearded organizers.
|
# ? Jul 18, 2016 05:40 |