Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
Not quite so simple, sadly. This is what I'm working with:

Python code:
class UserProfileSerializer(serializers.ModelSerializer):
    email = serializers.EmailField(read_only=True, source='user.email')
    first_name = serializers.ReadOnlyField(source='user.first_name')
    last_name = serializers.ReadOnlyField(source='user.last_name')
    first_login = serializers.DateTimeField(read_only=True, 
                                            source='user.first_login')
    last_login = serializers.DateTimeField(read_only=True, 
                                           source='user.last_login')
    is_staff = serializers.ReadOnlyField(source='user.is_staff')
    is_superuser = serializers.ReadOnlyField(source='user.is_staff')

    class Meta:
        model = UserProfile
        fields = ('email', 'first_name', 'last_name', 'first_login', 
                  'last_login', 'is_staff', 'is_superuser')
        depth = 1


class SurveySerializer(serializers.ModelSerializer):
    time_period = serializers.PrimaryKeyRelatedField(read_only=True)
    users = UserProfileSerializer(read_only=True, 
                                  source='agency.user', 
                                  many=True)
    agency_name = serializers.StringRelatedField(read_only=True, 
                                                 source='agency.name')
    section_status = SurveySectionStatusSerializer(read_only=True, many=True)

    class Meta:
        model = Survey
What I want to do is find some way of restricting the initial queryset of UserProfileSerializer to non-staff users. This is GET only.

Adbot
ADBOT LOVES YOU

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
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.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

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?

Also, the filtering of the queryset happens on the Viewset, not on the Serializer. What does your Viewset that uses UserProfileSerializer look like?

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.

Hed
Mar 31, 2004

Fun Shoe
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:
# views.py
class NonStaffUserProfileList(generics.ListAPIView):
    serializer_class = UserProfileSerializer

    def get_queryset(self):
        return UserProfile.objects.filter(is_staff=False)

Storgar
Oct 31, 2011
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:
Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/lib/python2.7/site-packages/django/contrib/admin/templates/blog/index.html (File does not exist)
/usr/lib/python2.7/site-packages/django/contrib/auth/templates/blog/index.html (File does not exist)
/usr/lib/python2.7/site-packages/rest_framework/templates/blog/index.html (File does not exist)
/home/veda/Code/slackerparadise/vendor/django-rest-swagger/rest_framework_swagger/templates/blog/index.html (File does not exist)
under the "...app_directories.Loader" section, there should be "/home/veda/Code/slackerparadise/blog/templates/blog/index.html" (which is there in Windows). Let me know if I need to post any other info...

Also, I have o+x permission for /blog/templates...

Gounads
Mar 13, 2013

Where am I?
How did I get here?
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.

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

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?

code:
Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/lib/python2.7/site-packages/django/contrib/admin/templates/blog/index.html (File does not exist)
/usr/lib/python2.7/site-packages/django/contrib/auth/templates/blog/index.html (File does not exist)
/usr/lib/python2.7/site-packages/rest_framework/templates/blog/index.html (File does not exist)
/home/veda/Code/slackerparadise/vendor/django-rest-swagger/rest_framework_swagger/templates/blog/index.html (File does not exist)
under the "...app_directories.Loader" section, there should be "/home/veda/Code/slackerparadise/blog/templates/blog/index.html" (which is there in Windows). Let me know if I need to post any other info...

Also, I have o+x permission for /blog/templates...

You should avoid hard-coding your paths. Try something like:

code:
from os.path import abspath, basename, dirname, join, normpath
from sys import path


########## PATH CONFIGURATION
# Absolute filesystem path to the Django project directory:
DJANGO_ROOT = dirname(dirname(abspath(__file__)))

# Absolute filesystem path to the top-level project folder:
SITE_ROOT = dirname(DJANGO_ROOT)

TEMPLATE_DIRS = (
    normpath(join(SITE_ROOT, 'templates')),
You can have a look at https://github.com/twoscoops/django-twoscoops-project/tree/develop/project_name/project_name/settings for a good example of a 1.6 settings layout. I haven't converted anything from 1.6 to 1.7 yet, but I don't think anything should be massively wrong in that link.

Storgar
Oct 31, 2011
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.

Slashes and filesystem permissions seem like a good hunch. I'll keep trying things.

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 :negative:

Storgar fucked around with this message at 04:14 on Dec 14, 2014

Hed
Mar 31, 2004

Fun Shoe
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.

Storgar
Oct 31, 2011
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!

I am not a book
Mar 9, 2013
Are there any blog apps that you all recommend? I'm looking for something that's mature but not abandoned.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
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:
from django.db import models
from django.contrib.auth.models import User

class ExtraCrapUser(models.Model):
   user = models.OneToOneField(User)
   my_special_snowflake = models.CharField(max_length=25)
When I am letting users create accounts, I have a my_special_snowflake field in the form, but what is the best way to save that data when I create the User? I can think of a whole lot of ways to do that, but I'm unclear on what makes the most sense. :google: keeps giving me results that say "you should do a OneToOne relationship to User!!" but nothing about actually when and how to go about saving the extra fields. Also, my Django is really rusty, so that's not helping. :D

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
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:
from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=User)
def create_profile(sender, **kwargs):
    user = kwargs.get('instance')
    if user.pk:
        profile, created = ExtraCrapUser.objects.get_or_create(user=user)
Then you just need to make sure that you're saving the User form part of your FormSet first, let the signal create the profile, then save the profile part of the FormSet.

I can give more details if anything I wrote is confusing.

Blinkz0rz fucked around with this message at 17:42 on Dec 26, 2014

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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.

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:
from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=User)
def create_profile(sender, **kwargs):
    user = kwargs.get('instance')
    if user.pk:
        profile, created = ExtraCrapUser.objects.get_or_create(user=user)
Then you just need to make sure that you're saving the User form part of your FormSet first, let the signal create the profile, then save the profile part of the FormSet.

I can give more details if anything I wrote is confusing.

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

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
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?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Blinkz0rz posted:

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?

Yep. I got it working by doing roughly the following:

Python code:
# project.settings
AUTH_PROFILE_MODULE = 'myapp.ExtraCrapUser' #this is important!!!


#models.py
from django.db.models.signals import post_save
...

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        ExtraCrapUser.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

#views.py
class NewUserFormView(FormView):
    form_class = NewUserForm
    ...

    def form_valid(self, form):
        new_user = User.objects.create_user(
            form.cleaned_data['username'], form.cleaned_data['email'],  form.cleaned_data['password']
        )
        profile = new_user.extracrapuser
        profile.special_snowflake = form.cleaned_data['special_snowlake']
        profile.save()
        return super(NewUserFormView, self).form_valid(form)
It makes sense to me now, but I didn't have a grasp on the moving parts at first. Thanks again for pointing me in the right direction!

supermikhail
Nov 17, 2012


"It's video games, Scully."
Video games?"
"He enlists the help of strangers to make his perfect video game. When he gets bored of an idea, he murders them and moves on to the next, learning nothing in the process."
"Hmm... interesting."
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:
problem_statement=9465+÷+7
What I want to do with it is turn the numbers into a tuple. In other situations I accomplish it with
code:
(op1, op2) = map(int, problem_statement.split('x')
except in the present situation the pesky ÷ screws it all up. The errors have to do with encoding, to be precise
code:
UnicodeDecodeError
...
'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
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?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
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:
class ThingTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = ThingType
        fields = ('name', 'id')

class ThingSerializer(serializers.ModelSerializer):
    thing_type = ThingTypeSerializer(read_only=True)

    class Meta:
        model = Thing
When I view my list of things, everything is great!

code:
[
  {    
    "id": 1,
    "name": "lolo",
    "thing_type": {
         "id": 3,
         "name": "The type of thing"
    }
  },
  {    
    "id": 2,
    "name": "zooopy",
    "thing_type": {
         "id": 2,
         "name": "Some other type of thing"
    }
  }
]
However, I can't seem to create a new Thing anymore! I used to POST {"name": "some new thing", "thing_type": 2} and all was well. Now it wants me to add all the fields for ThingType. If I make ThingType read_only=True it won't accept thing_type or thing_type_id as a parameter and complains "null value in column "thing_type_id" violates not-null constraint"

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

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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...

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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!

Now I've got to figure out if I want switch over...

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.

Hed
Mar 31, 2004

Fun Shoe
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.

supermikhail
Nov 17, 2012


"It's video games, Scully."
Video games?"
"He enlists the help of strangers to make his perfect video game. When he gets bored of an idea, he murders them and moves on to the next, learning nothing in the process."
"Hmm... interesting."
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:
    problem_statement = request.GET['problem_statement']
    problem = problem_type.parse(problem_statement)
After which the model for problem_type does this (now):
code:
    @staticmethod
    def parse(problem_statement):
        matchObj = re.search(r'(\b\d+\b).+(\b\d+\b)', problem_statement)
        (op1, op2) = (int(matchObj.group(1)), int(matchObj.group(2)))
        return (op1, op2)
It used to be initially like that:
code:
    @staticmethod
    def parse(problem_statement):
        (op1, op2) = map(int, problem_statement.split("&divide"))
        return (op1, op2)
'& divide' because that's what I sent out into the ether, but it turned out it doesn't come back unharmed. The error always reffered (in order of appearance) to problem_type.parse and (op1,op2) = map... But with my fudging I've seen quite a few different error variants.

I'm not sure everything above matters anymore, because the current solution seems to be working and looking quite neatly. But :effort:.

ufarn
May 30, 2009
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 ...

Storgar
Oct 31, 2011
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

Hed
Mar 31, 2004

Fun Shoe

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?

There has to be a better way than goddamn Drupal ...

I really like Mezzanine/cartridge

duck hunt
Dec 22, 2010

Storgar posted:

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.

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.

Hed
Mar 31, 2004

Fun Shoe
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.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

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

Hed
Mar 31, 2004

Fun Shoe
Cheers!

duck monster
Dec 15, 2004

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.

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop
I'm working on 1.7, with the new limit_choices_to foreignkey constraint.

Simplified:

Python code:
class Tag(Model):
   name = CharField(max_length=255)

class Widget(Model):
   ...

class WidgetTags(Model):
   widget = ForeignKey(Widget, unique=False)
   tag    = ForeignKey(Tag, unique=False, limit_choices_to=Q(???)

   class Meta:
      unique_together('widget', 'tag', )
What I want is the form dropdown limited to tags that the widget doesn't already have.

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

Ahz
Jun 17, 2001
PUT MY CART BACK? I'M BETTER THAN THAT AND YOU! WHERE IS MY BUTLER?!
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.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Use Mandrill, less likelihood of server blacklisting, reliable speed, up to 12000 per month free.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I have no idea how it compares to Mandrill, but there's also SendGrid.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
What do y'all suggest for logging an in-house app that sees fairly regular daily use?

Gounads
Mar 13, 2013

Where am I?
How did I get here?
If you're using AWS, they've got a service for email as well.

NtotheTC
Dec 31, 2007


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.

Adbot
ADBOT LOVES YOU

xpander
Sep 2, 2004
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:
self.fields['village'].queryset = Village.objects.order_by('name')
self.fields['commune'].queryset = Commune.objects.order_by('name')
self.fields['district'].queryset = District.objects.order_by('name')
self.fields['province'].queryset = Province.objects.order_by('name')
I emptied the querysets by changing those to none(). I haven't changed the view at all, other than to throw in some debugging code.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply