|
Not quite so simple, sadly. This is what I'm working with:Python code:
|
# ? Dec 10, 2014 01:46 |
|
|
# ? Jun 5, 2024 06:52 |
|
Really what I'm trying to accomplish is to get the first first_login date of all users working on that survey but I don't know if that's possible. I'm using drf generic views, not viewsets.
|
# ? Dec 10, 2014 01:52 |
I don't think you need to repeat all your field definitions there, why not just specify a list of read_only_fields on your serializer meta?quote:What I want to do is find some way of restricting the initial queryset of UserProfileSerializer to non-staff users. This is GET only. What do you mean by the initial queryset? Also, the filtering of the queryset happens on the Viewset, not on the Serializer. What does your Viewset that uses UserProfileSerializer look like? edit: quote:I'm using drf generic views, not viewsets. Any particular reason? It seems like viewsets might be more convenient for your use
|
|
# ? Dec 10, 2014 02:09 |
|
fletcher posted:I don't think you need to repeat all your field definitions there, why not just specify a list of read_only_fields on your serializer meta? I'm using a custom user model that's got a one-to-one relationship with the UserProfile object. quote:What do you mean by the initial queryset? I guess whatever the serializer works on. I'm still not sure how drf actually processes nested serializers. Like in my case, when you pass the Survey queryset from my view into the SurveySerializer where does drf traverse the relationship and grab the related objects and how do I intercede and decide what it should take and what it shouldn't? quote:Any particular reason? It seems like viewsets might be more convenient for your use Convenience? The mixins are pretty nice. I'll take a look at viewsets, though. I remember wondering why anyone would choose one over the other as they seem very similar.
|
# ? Dec 10, 2014 02:24 |
|
I think one of the problems we're having with answering that question is it generally doesn't make sense to filter things in the serializer. Another way of thinking about that is that your UserProfile serializer should know how to serialize/deserialize UserProfile objects well, and nothing else. So in that sense your UserProfileSerializer looks fine if a little verbose. To restrict your GET to whatever, then the most straightforward way is to filter your view in the manner fletcher suggested: Python code:
|
# ? Dec 10, 2014 04:01 |
|
I've been developing with Django 1.7.1 on Windows 7 and then I decided to take a look at it on a different computer running Django 1.7.1 on ArchLinux. I can't get the templates to load. According to the post mortem, it's because the app directories loader isn't looking into the "templates/" subdirectory of each app. I just did a pull so both repos should have identical code. Has anyone run into this before?code:
Also, I have o+x permission for /blog/templates...
|
# ? Dec 12, 2014 10:16 |
|
Don't know if it's your problem or not, but when I hear platform-specific file things like this I think of either the wrong slashes being used (always use / in django) or case-sensitivity where one filesystem is, and the other isn't, and a mis-capitalized path messes things up on one but not the other.
|
# ? Dec 12, 2014 16:40 |
|
Storgar posted:I've been developing with Django 1.7.1 on Windows 7 and then I decided to take a look at it on a different computer running Django 1.7.1 on ArchLinux. I can't get the templates to load. According to the post mortem, it's because the app directories loader isn't looking into the "templates/" subdirectory of each app. I just did a pull so both repos should have identical code. Has anyone run into this before? You should avoid hard-coding your paths. Try something like: code:
|
# ? Dec 12, 2014 17:03 |
|
Thanks, I do generate paths similarly to the above link using Python's os agnostic functions. That's good stuff right there. You're looking at the post mortem on my template error that's showing me all the calculated paths its checking. But my problem isn't quite that. According to the Django documentation, every app should have a default directory called "templates" inside each app directory. I have one app called "blog" and a bunch of templates in "blog/templates". Django should automatically check in this template directory out of the box without me having to change any settings, but for some reason it's not doing that on my linux installation. e. I hardcoded the path, and I get a reverse url error. Upon trying to load a second page, I am realizing that for some reason, my blog app doesn't seem to be loading into Django's framework. It's confusing to me because it works in Windows and "blog" is in the installed apps section of my settings... ee. I GOT IT WORKING BUT I DONT KNOW HOW Storgar fucked around with this message at 04:14 on Dec 14, 2014 |
# ? Dec 13, 2014 09:09 |
|
I had a problem a few weeks ago where I had an app either without templates or something with higher in the app order list and it seemed like the framework just stopped checking after that. I didn't mess with it enough to debug that issue because I had already wasted enough time on it. Anyway, you might try shuffling your app order and seeing if the problem returns.
|
# ? Dec 14, 2014 17:21 |
|
Oh. What happened between my post and when it was working was I took out a few lines of unnecessary paths and applied a migration. I had added a python path using sys.path.insert(0, APP_DIR) where the filesystem location of APP_DIR no longer existed. For some reason, Windows Django does not choke on it. I added those lines back in just now and I'm getting the same errors! So, yeah, it was that ^^. Problem solved. Thanks guys!
|
# ? Dec 15, 2014 03:45 |
|
Are there any blog apps that you all recommend? I'm looking for something that's mature but not abandoned.
|
# ? Dec 22, 2014 03:47 |
|
Semi-dumb best practices question. I am extending the User model thusly, which the docs seem to tell me is a good idea:Python code:
|
# ? Dec 26, 2014 17:18 |
|
You should be using FormSet to put your User ModelForm and your ExtraCrapUser ModelForm into one form-like object. That way when you're saving the FormSet you're saving both models. The key will be how you handle creating new profiles when you create users. If you specify a reverse argument on your OneToOneField you can use the post_save signal with your user model specified as the sender. In your signals.py do something like this: Python code:
I can give more details if anything I wrote is confusing. Blinkz0rz fucked around with this message at 17:42 on Dec 26, 2014 |
# ? Dec 26, 2014 17:39 |
|
Blinkz0rz posted:You should be using FormSet to put your User ModelForm and your ExtraCrapUser ModelForm into one form-like object. That way when you're saving the FormSet you're saving both models. What is this "profile" you speak of.... This is why I am having trouble with this, I think. Every post / link / whatever glosses over a lot. That said, I should be able to figure it all out with a bunch more reading and searches based on what you said. Thanks! https://www.youtube.com/watch?v=2i1LFWewbUU
|
# ? Dec 26, 2014 18:49 |
|
Sorry, when I say profile I'm referring to your ExtraCrapUser model. Because your User and ExtraCrapUser are effectively communicating linked information in different objects, you need to figure out how to keep them synchronized. The standard way of doing it is to present their creation (i.e. a "New User" form) together using a FormSet and then handle the save order in an overridden FormSet.save() method. The suggestion I had about using signals is simply a way to make sure that your ExtraCrapUser actually exists when the User exists. You could do the exact same thing in FormSet.save() Does that make sense?
|
# ? Dec 26, 2014 21:06 |
|
Blinkz0rz posted:Sorry, when I say profile I'm referring to your ExtraCrapUser model. Yep. I got it working by doing roughly the following: Python code:
|
# ? Dec 26, 2014 23:46 |
|
For now (and maybe that's a bad idea that'll be somehow corrected in the future), I have requests that contain lines like the following:code:
code:
code:
|
# ? Jan 3, 2015 15:09 |
|
Django Rest Framework question after switching to 3.x from 2.4.x to fight the "pre_save never gets called" bug. I have two serializers like so: Python code:
code:
So how do I get my ThingType to show like I want while being able to POST an id to thing_type when I make a new Thing? Do I actually have to now create multiple serializers, one for listing / details and one for creating? If so, how the hell do you do that? EDIT: I'd love a different answer than this, but I wound up finally getting the right search term and finding this: http://stackoverflow.com/a/22922156/167655 which seems to indicate that I do need to write multiple serializers for creating things now. I used that multiple serializer viewset mixin and things are working now. Seems like a step backwards from 2.4, but I'm dumb so who knows. Lumpy fucked around with this message at 22:54 on Jan 3, 2015 |
# ? Jan 3, 2015 21:49 |
|
I've been in heads-down crunch mode on my drf-using app for a month (or two) now and I didn't even realize 3.x was out! Now I've got to figure out if I want switch over...
|
# ? Jan 4, 2015 05:45 |
|
Thermopyle posted:I've been in heads-down crunch mode on my drf-using app for a month (or two) now and I didn't even realize 3.x was out! If it ain't broke, don't fix it. I had to change a bunch of stuff to handle errors all over the place after the upgrade, and ran into the issue I asked about on top of It.
|
# ? Jan 4, 2015 07:25 |
|
I'm going to wait for 3.1 after messing around with it a bit yesterday for some of the nested/related field goodness to work a bit more to my liking.supermikhail posted:But I'm not sure what exactly it wants from me. And whether I can do anything. If I understand it correctly, it receives a unicode string which it needs to convert to ascii, but there is no such character in ascii? Can you paste your view code or whatever actually generates the error? It looks like the error you're having is caused by a string encoded in UTF-8 being decoded through ASCII.
|
# ? Jan 4, 2015 19:08 |
|
Oh. I've kind of just solved it right now on my own in a possibly very roundabout way (and was going to update my previous post). Basically, the view takes the aforementioned expression ('problem_statement=9465+÷+7') and code:
code:
code:
I'm not sure everything above matters anymore, because the current solution seems to be working and looking quite neatly. But .
|
# ? Jan 4, 2015 19:45 |
|
The people at work use Drupal for e-commerce client solutions, but as I hate Drupal, I was wondering what the best Django module - that isn't straight-up Shopify - would be? There has to be a better way than goddamn Drupal ...
|
# ? Jan 10, 2015 22:35 |
|
Gonna butt in with another question... This page talks about deploying static files with Django. I don't understand why I need to do this? Does it give me some sort of security/performance benefit? Right now I'm building my website and just moving assets into the static files folder when I add them to my website. Isn't this basically what the page above is telling me to do if I didn't already move them in? Or is it important that all my static files are in the same exact folder and no subfolders? e. Oh. I think I'm getting a better idea. According to this page, it seems like they just meant that the static files should be handled by dedicated server software (apache, etc) for production machines. Related to the "runserver script is for debug only" thing. Storgar fucked around with this message at 10:00 on Jan 11, 2015 |
# ? Jan 11, 2015 01:53 |
|
ufarn posted:The people at work use Drupal for e-commerce client solutions, but as I hate Drupal, I was wondering what the best Django module - that isn't straight-up Shopify - would be? I really like Mezzanine/cartridge
|
# ? Jan 11, 2015 16:05 |
|
Storgar posted:Gonna butt in with another question... Django isn't really setup out of the box for serving static files. The "python manange.py runserver" that we are used to during development works great for development, but you really want to use a server that is more specialized for static files when you go live. You get better performance serving static files from something that is better built for that. On the security side, because the development server is setup for development, it wasn't really meant to be secure. Plus, when you hit your static files in things like {{ STATIC_URL }} OR {% static %} your server-side python code is processing things which adds extra overhead that a dedicated static files server doesn't have.
|
# ? Jan 15, 2015 07:27 |
|
What packages do you guys use for instance-level security? I'm thinking of something like where I can set security bits on an object and have a QuerySet only return rows that a user can see, as well as ensure DetailViews don't work for forbidden objects.
|
# ? Jan 16, 2015 04:44 |
|
Hed posted:What packages do you guys use for instance-level security? I'm thinking of something like where I can set security bits on an object and have a QuerySet only return rows that a user can see, as well as ensure DetailViews don't work for forbidden objects. https://github.com/lukaszb/django-guardian
|
# ? Jan 16, 2015 13:08 |
|
Cheers!
|
# ? Jan 16, 2015 20:45 |
|
I'm back in the tastypie camp these days. DRF is niice with its API screens and stuff, but I just found tastiepie was so much easier to do complex poo poo with. With all that said, I'd rather chew my own arms off than do another large scale AngularJS / rest-backend project again. Holy gently caress how do people cope with Javascripts profound retardedness and not revert to alcoholism? I'd finish my job each day and want to invade the local hipster bar to throw chairs at bearded youth shouting "GET THE gently caress OUT OF I.T. YOU CUNTS", during that project. Fortunately I was too tired to do anything so .... rational.... as that.
|
# ? Jan 19, 2015 02:10 |
|
I'm working on 1.7, with the new limit_choices_to foreignkey constraint. Simplified: Python code:
If that's not possible with limit_choices_to I'll write a custom form widget. Edit: Is there a term for a pair of multi-select boxes with left and right arrows that 'moves' a selection from one to the other? It's a pretty common design but I don't know what it's called. Harik fucked around with this message at 20:57 on Jan 23, 2015 |
# ? Jan 23, 2015 20:54 |
|
Roll my own SMTP for mailouts or use a 3rd party? For the most part it will likely be low volume mailing, just registrations, activations, sales of a low traffic site.
|
# ? Jan 29, 2015 17:32 |
|
Use Mandrill, less likelihood of server blacklisting, reliable speed, up to 12000 per month free.
|
# ? Jan 29, 2015 18:08 |
|
I have no idea how it compares to Mandrill, but there's also SendGrid.
|
# ? Jan 29, 2015 18:49 |
|
Anyone have anything to say about concurrency control when using DRF? I see that drf-extensions has a bit about it, but this is really the first time I've had to think about concurrent editing of objects so I'm not sure what I'm looking for. edit: wow i'm double posting a lot today
|
# ? Jan 29, 2015 19:54 |
|
What do y'all suggest for logging an in-house app that sees fairly regular daily use?
|
# ? Jan 29, 2015 22:25 |
|
If you're using AWS, they've got a service for email as well.
|
# ? Jan 30, 2015 15:36 |
|
The March Hare posted:What do y'all suggest for logging an in-house app that sees fairly regular daily use? Sentry is nice, gives interactive debug pages etc.
|
# ? Jan 31, 2015 10:41 |
|
|
# ? Jun 5, 2024 06:52 |
|
I'm doing a small upgrade to an existing Django site, and am having an issue I can't seem to figure out. There is a customer form which has some select boxes representing different parts of an address(province, district, commune, village). I'm replacing the way those dropdowns are populated - previously Django was doing so with a ModelForm. My modifications are to use JavaScript to pull data from a simple TastyPie API I whipped up, populate only the top-level select(province) then cascade and filter the next one when a selection is made, etc. The front-end changes seem to be working fine, but the problem arises on form submission: the form isn't validating, it's returning "Select a valid choice. That choice is not one of the available choices."(this is Bootstrap btw) for each of the boxes. I've examined the post data via Django Debug Toolbar and printing it to the console, and the values are identical to those when the form gets submitted the old way. What am I missing here? I do need some more logic in the JS to prefill the boxes when loading existing customer data, but nothing should really have changed regarding form submission. This is how the data was being loaded initially: code:
|
# ? Feb 9, 2015 23:32 |