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
MonkeyMaker
May 22, 2006

What's your poison, sir?

NtotheTC posted:

I'd quite like to do some open-source contributing centered around Django. Is there some sort of list or resource to find a project that is looking for contributors?

Most projects are pretty happy with contributors.

I know django-admin2 has been undergoing a lot of work lately. Django has a couple of blocking bugs before 1.6 can come out, if you want to jump into the deep-end.

Adbot
ADBOT LOVES YOU

ufarn
May 30, 2009
django-registration is a really, really important app with really, really poor maintenance.

Not that I'm saying that Ubernostrum is the kind of guy who welcomes feedback, but it's definitely something important that needs help.

MonkeyMaker
May 22, 2006

What's your poison, sir?

ufarn posted:

django-registration is a really, really important app with really, really poor maintenance.

Not that I'm saying that Ubernostrum is the kind of guy who welcomes feedback, but it's definitely something important that needs help.

I'd be surprised if he accepted patches, honestly.

PyDanny has been recommending django-allauth for awhile now and I plan on using it if/when I need registration.

Contribute to that ;)

django-braces is always open for patches </toot-toot>

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

MonkeyMaker posted:

I'd be surprised if he accepted patches, honestly.

My pull request has been open for a year and a half now.

ufarn
May 30, 2009
I can understand part of his frustration, because a lot of people really don't bother to read the history of requests, but he's the most reclusive maintainer I can think of.

Does django-registration 1.0 and the upgrade documentation even been officially released at this point?

Last I saw, it looked like it was out, but there was no guide for upgrading from 0.8 to 1.0.

I should really stop depending on django-registration ...

MonkeyMaker
May 22, 2006

What's your poison, sir?

ufarn posted:

I can understand part of his frustration, because a lot of people really don't bother to read the history of requests, but he's the most reclusive maintainer I can think of.

Does django-registration 1.0 and the upgrade documentation even been officially released at this point?

Last I saw, it looked like it was out, but there was no guide for upgrading from 0.8 to 1.0.

I should really stop depending on django-registration ...

1.0 is officially out, I do believe. It doesn't support Django 1.5's custom User model, though, even with being released after 1.5.

Duke of Idaho
Mar 25, 2012
I'm currently making a website to learn Django and wondering on what I should be documenting? I have no plans on making this an open source project, but feel that this would be a good time to learn about writing documentation. I know about docstrings and sphinx.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Duke of Idaho posted:

I'm currently making a website to learn Django and wondering on what I should be documenting? I have no plans on making this an open source project, but feel that this would be a good time to learn about writing documentation. I know about docstrings and sphinx.

Like what should you be documenting for yourself?

Everything that you look up in the docs and/or every time you use `pdb`. Write down what you looked up and either what the answer was or a link to the answer. Also write down what you did that made the bug happen.

Write tests for your bugs.

ufarn
May 30, 2009
Apropos, Ubernostrum just announced that django-registration is basically dead and available for ownership.

Thermopyle
Jul 1, 2003

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


I haven't looked at its code at all, but given that its so old, and it really doesn't seem like that complicated of a thing...I'd just rewrite it from scratch instead of taking over the old code.

ufarn
May 30, 2009

Thermopyle posted:

I haven't looked at its code at all, but given that its so old, and it really doesn't seem like that complicated of a thing...I'd just rewrite it from scratch instead of taking over the old code.
To be fair to him, at lot of the purpose has been obviated with the new User model.

I just have to unlearn the django-registration method before applying the new (old, argh) model first.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
Well that's disconcerting, it's scary when you're just finishing up a project and one of your dependencies is already no longer supported.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Cheekio posted:

Well that's disconcerting, it's scary when you're just finishing up a project and one of your dependencies is already no longer supported.

It's not like the django-registration workflow is difficult to NIH.

ufarn
May 30, 2009

Cheekio posted:

Well that's disconcerting, it's scary when you're just finishing up a project and one of your dependencies is already no longer supported.
I don't think there's ever been a security-related update to the app. It's more about having to move on to future/1.5-proof your projects than anything else.

NtotheTC
Dec 31, 2007


Has anyone had experience using Google Interactive Map with Django? I want users to be able to set markers for things (in this case pictures) that other users of the map will be able to see. Django-easy-maps looks like it provides some of the functionality I need. Having not used the Google Map API I'm not sure how easy it is to do things from within Django itself or whether it will require a lot of AJAX to do things like set the HTML of markers etc.

Can I have create one big map that contains all the user created markers and have all the marker information stored on googles side? There are click events, so I could have one of those bring up a form that they can upload a picture to along with the co-ordinates that were clicked on.. that can get submitted to django and then on confirmation of the save the marker could be added.

Or is it the case that I have to populate those markers manually every time I load up a map from the lat/lng values I have stored in the database? That strikes me as a preferable/more maintainable solution, but I'm worried about the loading times. That would remove the need to intercept the delete API call from Google Maps too however.

NtotheTC fucked around with this message at 11:57 on Aug 29, 2013

Baby Nanny
Jan 4, 2007
ftw m8.

NtotheTC posted:

Has anyone had experience using Google Interactive Map with Django? I want users to be able to set markers for things (in this case pictures) that other users of the map will be able to see. Django-easy-maps looks like it provides some of the functionality I need. Having not used the Google Map API I'm not sure how easy it is to do things from within Django itself or whether it will require a lot of AJAX to do things like set the HTML of markers etc.

Can I have create one big map that contains all the user created markers and have all the marker information stored on googles side? There are click events, so I could have one of those bring up a form that they can upload a picture to along with the co-ordinates that were clicked on.. that can get submitted to django and then on confirmation of the save the marker could be added.

Or is it the case that I have to populate those markers manually every time I load up a map from the lat/lng values I have stored in the database? That strikes me as a preferable/more maintainable solution, but I'm worried about the loading times. That would remove the need to intercept the delete API call from Google Maps too however.

Ya django actually has some neat stuff built in to do this. Do a search for geodjango. I actually just did something similar where I stored the lat lng points in a geodjango model and wrote a little api that accepted a google maps bounding box as an argument and returned all points in said box from my database. It was surprisingly simple using googles api with geodjango and it gives you the benefit of only loading markers in the currently seen map area

NtotheTC
Dec 31, 2007


GeoDjango does look interesting.

To elaborate, I'm going to have a picture model, which includes a user uploaded photo, timestamp, and lat/lng coordinates. So I guess I could make that a GeoDjango model:

Python code:
from django.contrib.gis.db import models

class Picture(models.Model):
    ... # blah
    lat_lng = models.PointField()
    ... # blah
Maybe that will be enough to work with on my google map so I won't even need to use django-easy-map. although I quite like the widgets they have for entering data. GeoDjango requires a spatial DB right? So I'd potentially have to get my head around setting up postGIS to use it as well.

If your project is open source and you don't mind me having a look round it I'd love to see how you communicated with the google API etc.

NtotheTC
Dec 31, 2007


As an aside, with django-registration getting dumped by the creator, what is the best alternative now for a simple drop-in registration system? Is django-registration still a decent choice or should people be moving to a different app.

MonkeyMaker
May 22, 2006

What's your poison, sir?

NtotheTC posted:

As an aside, with django-registration getting dumped by the creator, what is the best alternative now for a simple drop-in registration system? Is django-registration still a decent choice or should people be moving to a different app.

django-socialauth is great if you don't want to deal with registration/login yourself.

I hear good things about django-allauth, too, but haven't used it myself yet.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
Anyone going to DjangoCon? I'm currently spending too much money on in-flight wifi en route to Chicago. Nothing like putting some final hours of polish (read:making from scratch) a portfolio site while hopping planes.

etcetera08
Sep 11, 2008

Yep, headed there tomorrow morning.

NtotheTC
Dec 31, 2007


Cheekio posted:

Anyone going to DjangoCon? I'm currently spending too much money on in-flight wifi en route to Chicago. Nothing like putting some final hours of polish (read:making from scratch) a portfolio site while hopping planes.

Edit: Is there a livestream of any of the talks at djangocon?

Funnily enough I've read a few blogs recently that championed the "write code on a plane" technique to software development.

http://www.campaul.net/blog/2013/08/16/flakes-on-a-plane/
http://doppnet.com/2011/04/coding-while-on-the-plane/

(The trick is not to pay for wifi)

I'm not sure I could work like that. If I was required to write code without the internet my first step would be to google "How to write code without the internet".

NtotheTC fucked around with this message at 11:23 on Sep 2, 2013

Thermopyle
Jul 1, 2003

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

I just can't code on a laptop anymore without being constantly frustrated. I'm too used to multiple monitors.

ufarn
May 30, 2009

Thermopyle posted:

I just can't code on a laptop anymore without being constantly frustrated. I'm too used to multiple monitors.
Being able to stick a window to one half of the screen is the only way I can navigate now. Even then, there's never enough screen real estate.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Cheekio posted:

Anyone going to DjangoCon? I'm currently spending too much money on in-flight wifi en route to Chicago. Nothing like putting some final hours of polish (read:making from scratch) a portfolio site while hopping planes.

Nope, not this year. Too expensive, didn't have a talk I really wanted to give, and it always conflicts with the first day of school, making me feel like a horrible dad.

Say hi to any Lincoln Loop people you meet there!

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.

NtotheTC posted:

Edit: Is there a livestream of any of the talks at djangocon?

Funnily enough I've read a few blogs recently that championed the "write code on a plane" technique to software development.

http://www.campaul.net/blog/2013/08/16/flakes-on-a-plane/
http://doppnet.com/2011/04/coding-while-on-the-plane/

(The trick is not to pay for wifi)

I'm not sure I could work like that. If I was required to write code without the internet my first step would be to google "How to write code without the internet".

A) Right now it's just the paid tutorials, so they're not being broadcast. The real conference starts tomorrow and I'll give a heads up in the thread if I see any good AV setups.

B) I've been looking for content to kick off a new blog with and I think those two articles are perfect.

ufarn posted:

Being able to stick a window to one half of the screen is the only way I can navigate now. Even then, there's never enough screen real estate.

I'm hoping that coding on one screen can be 're-learned', like a practicable skill that eventually you're just stuck with a baseline level of proficiency of. Of course, my desktops are all qwerty while my laptops are all dvorak because of a similar line of thinking, but I can't imagine this turning out quite so badly.

Pythagoras a trois fucked around with this message at 18:06 on Sep 2, 2013

MonkeyMaker
May 22, 2006

What's your poison, sir?
I do probably 85% of all of my development on one screen. I have a second monitor but don't hook it up all the time. When I do, it's for my editor only since it's turned 90º to portrait.

My secrets are a good window manager/layout control and, at least on the Mac, heavy use of full-screen mode.

the
Jul 18, 2004

by Cowcaster
Do you guys know if I can use Django with Canopy? I'm just comfortable with the development environment, and I use it with my scientific viz stuff. In the list of downloadable packages in Canopy there's a "Django 1.3.1," but I see the latest version on Django's website is 1.5.2. Just wonder if I can import the package somehow. Thanks.

duck monster
Dec 15, 2004

NtotheTC posted:

Edit: Is there a livestream of any of the talks at djangocon?

Funnily enough I've read a few blogs recently that championed the "write code on a plane" technique to software development.

http://www.campaul.net/blog/2013/08/16/flakes-on-a-plane/
http://doppnet.com/2011/04/coding-while-on-the-plane/

(The trick is not to pay for wifi)

I'm not sure I could work like that. If I was required to write code without the internet my first step would be to google "How to write code without the internet".

keep a local copy of whatever manuals you might need. I often code with my wifi turned off just to avoid distraction.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
There's a pretty hefty camera pointing at the invited speakers, but there's no live stream of the conference as far as I can tell. The 10am keynote (which I slept through) was apparently more about not getting in trouble with copyright and branding than it was the direction of Django (which makes me happy I slept through it). Seems like Day 1? is pretty tame.

The Day 0? tutorials yesterday were awesome though. The TDD tutorial yesterday was friggin awesome, I had read a handful of the speakers' book and got about as far as self-learning could take me, and now I feel confident that TDD is something I absolutely want to use going forward.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Cheekio posted:

There's a pretty hefty camera pointing at the invited speakers, but there's no live stream of the conference as far as I can tell. The 10am keynote (which I slept through) was apparently more about not getting in trouble with copyright and branding than it was the direction of Django (which makes me happy I slept through it). Seems like Day 1? is pretty tame.

The Day 0? tutorials yesterday were awesome though. The TDD tutorial yesterday was friggin awesome, I had read a handful of the speakers' book and got about as far as self-learning could take me, and now I feel confident that TDD is something I absolutely want to use going forward.

The keynotes rarely have anything to do with day-to-day Django development. Often they're not even by developers (last year had a Congressman, for example). The videos will likely be available a month or two after the conference is over. That's when they usually go live.

Thermopyle
Jul 1, 2003

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

What's a good way to ensure model validation is run when you're creating instances, but not using a form?

For example, I have celery tasks that create model instances, but methods like .save() or .get_or_create() don't run .clean().

Of course, I can call .clean() myself, but I'm just wondering if there is a way anyone likes more.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Thermopyle posted:

What's a good way to ensure model validation is run when you're creating instances, but not using a form?

For example, I have celery tasks that create model instances, but methods like .save() or .get_or_create() don't run .clean().

Of course, I can call .clean() myself, but I'm just wondering if there is a way anyone likes more.

I just call self.clean() in the save() method.

It's ugly but it works.

EDIT:

Or, more cleanly, just call the model_instance.clean() in your Celery task.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I've got an ImageField that I want to use in Django REST Framework. How do I intercept the file upload so I can do things like rename the file or resize it and whatnot?

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

I've got an ImageField that I want to use in Django REST Framework. How do I intercept the file upload so I can do things like rename the file or resize it and whatnot?

Renaming should be done with the `upload_to` attribute on the model field.

I'd do resizing and stuff as a post_save signal.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Worked out great, thanks MonkeyMaker!

Got another question now...

My model has the following field:
code:
last_touched = models.DateTimeField(auto_now=True, auto_now_add=True)
But I get the following error when I try to save a record:

quote:

Warning: Field 'last_touched' doesn't have a default value

Shouldn't auto_now_add take care of that for me? So I also tried:
code:
last_touched = models.DateTimeField(default=datetime.datetime.now, auto_now=True, auto_now_add=True)
But I still got the error - what's the deal?

fletcher fucked around with this message at 20:20 on Sep 12, 2013

The March Hare
Oct 15, 2006

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

fletcher posted:

Worked out great, thanks MonkeyMaker!

Got another question now...

My model has the following field:
code:
last_touched = models.DateTimeField(auto_now=True, auto_now_add=True)
But I get the following error when I try to save a record:


Shouldn't auto_now_add take care of that for me? So I also tried:
code:
last_touched = models.DateTimeField(default=datetime.datetime.now, auto_now=True, auto_now_add=True)
But I still got the error - what's the deal?

You shouldn't have to do any of that crazy stuff with the default field at all. If it is just a field for an 'updated_at' type of thing try using:

code:
last_touched = models.DateTimeField(auto_now = True)
Also, are you using South? (because you should be)

The March Hare fucked around with this message at 21:31 on Sep 12, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Yup I've been using South from the get-go, it is pretty sweet!

Not sure what was up before with my auto_now, but it seems to be working now...

Got another question now. Django REST Framework appears to respect the blank=True/False on my model definitions, which is great. Is it possible to make that dynamic though? Like, I want it to be blank=True if some_field='foo', but if some_field was set to 'bar' then I want blank=False. How should I go about doing that? I can sorta get there with custom permissions but then it just returns a 403 permission denied, rather than a 400 bad request with useful error messages.

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

Yup I've been using South from the get-go, it is pretty sweet!

Not sure what was up before with my auto_now, but it seems to be working now...

Got another question now. Django REST Framework appears to respect the blank=True/False on my model definitions, which is great. Is it possible to make that dynamic though? Like, I want it to be blank=True if some_field='foo', but if some_field was set to 'bar' then I want blank=False. How should I go about doing that? I can sorta get there with custom permissions but then it just returns a 403 permission denied, rather than a 400 bad request with useful error messages.

If you only want that done when saved via the API, I'm not sure how to achieve that (since DRF doesn't really have a validation level), but you can override the clean method on the model to make sure at least one of the fields is filled in. I'm pretty sure DRF calls the model's clean method. If it doesn't, it's hacky but override the model's save and do it there.

Adbot
ADBOT LOVES YOU

Tavistock
Oct 30, 2010



Is this a good way of making entries only visible to their owners?

I feel as though there is a better way of handling it.
code:
### views.py
from django.views.generic import ListView, DetailView

from .models import Worksheet

from braces.views import LoginRequiredMixin

class SelfQueryMixin(object):
    def get_queryset(self):
        return self.model.objects.filter(owner=self.request.user)  #owner is django.contrib.auth.User foreignkey


class WorksheetListView(LoginRequiredMixin, SelfQueryMixin, ListView):
    model = Worksheet

class WorksheetDetailView(LoginRequiredMixin, SelfQueryMixin, DetailView):
    model = Worksheet

Also how can I off load this query class to my models.py?

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