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
No Safe Word
Feb 26, 2005

ashgromnies posted:

This post makes me want to learn Django... anyone know of a good cheap webhost that supports using it?

It works on Dreamhost, but a lot of goons hate dreamhost. And it's also not super-easy to get working on Dreamhost either.

But I've got my little ToME monster search app hosted on there and it runs just fine for the low volume it has to handle.

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

Although I would prefer something that didn't use the negative-space version of the logo, you can buy t-shirts and hoodies with the django logo on it here: http://django.spreadshirt.com/us/US/Shop/

If it was just the text in white I'd totally buy it :(

No Safe Word
Feb 26, 2005

greenskeleton posted:

http://www.djangoproject.com/documentation/model-api/#unique-for-date

Would that be what you're looking for?

Cool, I didn't even know such a thing existed, though:

django docs posted:

This is enforced at the Django admin-form level but not at the database level.

So, useful, but not db-uniqueness-assuring.

No Safe Word
Feb 26, 2005

ashgromnies posted:

EDIT: You know what... I love Django and the philosophy behind it but it's just not giving me what I need for development. I like working on things on the fly and implementing new features incrementally and Django offers no way to do that.

Sure, there's django-evolutions but I haven't gotten it to actually modify my tables - it always gives some cryptic error and I don't particularly feel like diving into it so I always end up wiping my database and resyncing.

I think I'm going back to Catalyst until Django gets a little bit more ready. I understand it's still not 1.0 yet, but the fact that you can't modify a model after it's been installed is a major sticking point for me.

The best way around that that I've found is to use the initial fixtures support, and just constantly dump/reload your database after schema changes. It's not perfect, but it works and isn't a lot of hassle. I do agree that it is a bit of a pain to have to introduce schema updates using the current setup otherwise.

No Safe Word
Feb 26, 2005

bitprophet posted:

Eclipse should definitely have Python support, not sure if it has Django specific support. Google around for "(python OR django) IDE" and I'm sure you'll find blog posts / discussions.


Eclipse has PyDev for Python support, nothing specific to Django that I've found. I actually prefer vim anyway though ;) (on Windows and Linux)

No Safe Word
Feb 26, 2005

http://djangopluggables.com/

Nice repository full of django apps you can plug into your site.

No Safe Word
Feb 26, 2005

Wulfeh posted:

I know this is a big vague, but hopefully someone may have an idea

code:
def contact_delete(request, file, contact_id): 
	
	contact_record = Contact
	contact_record = get_object_or_404(Contact, id=contact_id)
	contact_record.delete()
	
	return HttpResponseRedirect('/IR/' + file + '/contacts/')		
this raises an error stating "__init__ takes 2 args, but only 1 is given". I am not sure why/how 2 args are needed for deletion since all the examples show object.delete() as the way to delete

http://dpaste.com/45018/ - Full error message
http://dpaste.com/45019/ - My views, line 100 is the delete part

I'm not sure what contact_record = Contact is supposed to be doing, that's assigning the Contact model class to that variable, which then gets clobbered on the next line. It seems like it should possibly work, I don't know what __init__ is missing an arg, because the rest of it looks fine. It's kind of hard to unwind the full debug page dump from that pastebin. A screenshot would be more helpful (to me).

Also, from your views:
code:
		blammo = "SLAMMMOOOOO" #temp - cant do an empty if, but we'll need an if soon
It's funny, but you do know about pass, right? :)

No Safe Word
Feb 26, 2005

jarito posted:

Is there anyway to have syncdb just drop all the tables and reinsert them?
Yes, it's called initial fixtures, and basically you have to dump a serialized copy of the data into some files and put them in your FIXTURES_DIR and syncdb will pick them up (or loaddata).

loaddata docs have the information on how to create these fixtures here

the syncdb docs state:

quote:

syncdb will also search for and install any fixture named initial_data with an appropriate extension (e.g. json or xml). See the documentation for loaddata for details on the specification of fixture data files.

No Safe Word
Feb 26, 2005

liquidfury posted:

I having an issue with the database not updating the coloums when the models are changed. I saw in the thread that it is a known issue. Is there a way to force it to update? I am running Django 0.96.1

It's not just a known issue, it's just the way it's going to be. You have to recreate the database/tables when you make a change to the model. There was a schema-evolution branch in progress, but I don't know what is happening with it.

Alternately, manually make the changes :v:

No Safe Word
Feb 26, 2005

Bonus posted:

Yes but you see, this way I get to use the awesomely cool yes program.

With "no" as an argument for extra fun.

No Safe Word
Feb 26, 2005

James Bennett has apparently just finished up some of the final edits on his upcoming Django book, "Practical Django Projects". You may recognize him from some online sites as ubernostrum, but he's one of the higher profile Django devs and an all-around pretty bright guy. I'm sure his book will be very good, and for anyone looking to get started in the next few months it sounds like this may be a good book to have on the shelf.

No Safe Word
Feb 26, 2005

How fuzzy is it going to be? Are you only interested in exact search string matches? Or stuff that "kinda looks like it"? It might be something that you just pick a solution and run with it for a while to see if you hit a wall. My gut tells me it should be a separate model, but I'm having a tough time coming up with the best structure for it.

No Safe Word
Feb 26, 2005

Oh man, opportunity of a lifetime:



gently caress this job, I'm gonna go become a CTO!

So, since it's obviously spam for email addresses harvested from a Django-centric site ... anyone else get this?

No Safe Word
Feb 26, 2005

checkeredshawn posted:

In main/models.py when I use def __unicode__(self) instead of def __str__(self) in the Admin interface everything is just a "BlogPost object" or a "Category object", they don't show as the names that I've assigned to them, i.e. 'General' (example of a Category) or 'First blog post' (example of a BlogPost). Is there a way around this?

code:
    __str__ = __unicode__
(half-kidding, this is a workaround at best)

Though I thought it had all been fixed already, are you sure you're using the latest trunk? Not some branch where admin isn't fixed?

No Safe Word
Feb 26, 2005

If there are any Houston-area Django lovers in the area, the Houston Python Meetup group is having an Introduction to Django meetup Tuesday, August 26th. Come on out!

No Safe Word
Feb 26, 2005

Django 1.0 beta1

:woop:

No Safe Word
Feb 26, 2005

Jo posted:

I'm missing something really stupid, but I just can't figure it out.
In my views.py I have the line `results = DatabaseImage.objects.filer(blahblahblah)`, but I'm getting the error, "global name 'DatabaseImage' is not defined", despite having the entry DatabaseImage in my models.py. What could be causing this?

EDIT:
Relevant lines from views.py:
code:
searchHashObject = sha(file['content']);
searchHash = searchHashObject.hexdigest();
print searchHash;
results = DatabaseImage.objects.filter( hashValue=searchHash ); ...
if results.size > 0:
result = results[0];
Relevant lines from models.py:
code:
class DatabaseImage( models.Model ):
  # hashValue is sha256sum
  hashValue = models.CharField(maxlength = 64, primary_key = True);
  specialHash = models.CharField(maxlength = 128);
  image = models.ImageField(upload_to = '/home/jo/images');

You're missing the import to let it know what DatabaseImage is
code:
from appname.models import DatabaseImage

No Safe Word
Feb 26, 2005

Senso posted:

EDIT: Huuuh, I moved everything outside my home and put it in /opt, changed all the path definitions and now it works. Djangooooo :argh:
Was it maybe permissions?

No Safe Word
Feb 26, 2005

Django 1.0 is final

Release notes with what's new

edit: also Blog post!

No Safe Word fucked around with this message at 02:24 on Sep 4, 2008

No Safe Word
Feb 26, 2005

Not immediately but you should begin to migrate at some point.

And here's the link to the porting guide: http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide

No Safe Word
Feb 26, 2005

MononcQc posted:

Is there any way I can achieve that or I'll have to do it the long way without shortcuts? Maybe there's something I missed from the doc again.
The long way isn't really that long, since get_list_or_404 literally just does this:

code:
queryset = _get_queryset(klass)
obj_list = list(queryset.filter(*args, **kwargs))
if not obj_list:
    raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
return obj_list
And all _get_queryset does is allow the passed in klass arg to be either an actual Queryset or a Manager.

No Safe Word
Feb 26, 2005

For those who were lost as I was: http://www.djangopony.com/

My Little Pwny

No Safe Word
Feb 26, 2005

MEAT TREAT posted:

code:
from django.core.exceptions import *

	def __unicode__(self):
		try:
			if self.gamecharacter is not None: 
				return unicode(self.gamecharacter)
		except ObjectDoesNotExist:
			pass
		try:
			if self.gamemonster is not None: 
				return unicode(self.gamemonster)
		except ObjectDoesNotExist:
			pass
		return "Don't know what the gently caress this is"
This works now! :D

You could do:

code:
def __unicode__(self):
    return unicode(getattr(self, 'gamecharacter', getattr(self, 'gamemonster', 'No clue'))

No Safe Word
Feb 26, 2005

nbv4 posted:

I have a model that has about 80 boolean values. Whats the Right Way to group these fields together? For instance, 12 of those boolean values are column1_hide, column2_hide, etc, which correspond to which columns the user wants to hide somewhere on the site. I'm going to define a function on the model that returns an array of each column the user wants hidden. If the user has column5_hide and column6_hide set as true, I want that function to return ["column5", "column6"]. I want to be able to iterate through all the columns in the model, instead of doing something like:

code:
def make_column_hide_array(self):
    return_array = []
    if self.column1_hide:
        return_array.append("column1")

    if self.column2_hide:
        return_array.append("column2")

    [...]
which would violate DRY. Does any of this make sense?
Well first of all you probably shouldn't have a model with 80 boolean values, you should use a bitmask or some other way of storing all those booleans in one field that's not quite so cumbersome.

But if you just need some code to help do what you want with what you've got, this does the job:
code:
L = []
for i in range(1, 12):
    if getattr(self, 'column%d_hide' % i):
        L.append('column%d' % i)

No Safe Word
Feb 26, 2005

nbv4 posted:

Doesn't that still violate DRY? If you wanted to add an extra column, you'd have to change that 12 to a 13.

DRY means "Don't Repeat Yourself" so it doesn't violate DRY but it does violate the "don't put hardcoded constants in code" best practice. And yeah, data model changes requiring code changes isn't that wacky of an idea in the first place. If you're changing your data model, chances are it's going to require a redeployment of the code anyway.

If you want to get really hairy and ugly you can introspect the column names and do it that way but really the best option (in my opinion) is to not have a data model like that.

No Safe Word
Feb 26, 2005

ashgromnies posted:

I am trying to make an application for recipes using Django. I am starting simple and going from the tutorial but not getting the results I want. In a less strict framework I'd be able to represent what I want to easily but I'm having trouble figuring out how to do it the Django way while keeping the database clean and easy to query to prevent performance issues.
For this I generally just make the bridge table my own model, so I'd do something like:

code:
class RecipeIngredient(models.Model):
    recipe = models.ForeignKey(Recipe)
    ingredient = models.ForeignKey(Ingredient)
    amount = models.IntegerField()
    unit = models.ForeignKey(Unit)  # I know you have this as something different
                                    # but you should think about making this a lookup table
Also, these days (in Django 1.0+) you can wire up your admin stuff outside the models.py file - http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-objects

edit: vvvv well hot drat, those Django guys are pretty smart vvvv

No Safe Word fucked around with this message at 22:31 on Dec 25, 2008

No Safe Word
Feb 26, 2005

So Adrian and company are working on an updated Django Book, and the work-in-progress is online for everyone to see like last time, yay!

http://www.djangobook.com/en/2.0/

(Django Book 2.0 covers Django 1.0 :mmmhmm: )

No Safe Word
Feb 26, 2005

Has anybody had any luck extending the django.contrib.auth User model in their apps? I've been following the instructions on this blog post, but now when I try to login to the admin interface it's failing.

(note: this is with Django 1.0.2 final)

If I fire up the manage.py shell, and I do:

code:
In [1]: from django.contrib.auth.models import User

In [2]: User.objects.get(id=1)
Out[2]: <User: myusername>
I get back the right user and everything. Even if I reset the password in the shell and then try to login to the app, I just get:

admin app error message posted:

Please enter a correct username and password. Note that both fields are case-sensitive.
(yes, I put them both in correctly, checked caps lock and all that)

So I did a bit of digging:
code:
In [34]: from common.auth_backends import CustomUserModelBackend

In [35]: be = CustomUserModelBackend()

In [36]: be.authenticate(username='myusername', password='********')
Out[36]: <User: myusername>

In [37]:
What gives? According to the django docs on writing your own auth backend, this is exactly what should happen, and should be all that is necessary to happen. But the admin interface still craps out - is it just the admin interface being dumb? I haven't yet tried writing anything that uses authentication outside of the app, but if I can't figure anything else out that's probably my next step, though I get the feeling that won't work either.

No Safe Word
Feb 26, 2005

Sharktopus posted:

code:
from django.template import RequestContext
return render_to_response('app/success.html', RequestContext(request, {'newApp':newApp}))
will automatically include a host of variables (such as user) that you can then use without having to get them in every function.

They are incredibly useful.

And I could have sworn there was some sort of RequestContext middleware that either shipped with Django at some point or was on their code.djangoproject.com wiki somewhere that did this for every response automatically but I'll be damned if I can't find it. I don't want to reimplement it half-assed if it's already out there, but I can.

No Safe Word
Feb 26, 2005

Mashi posted:

Does anyone find the django ORM to be slow? I have some pages with minimal ORM usage taking about 30ms, and others that are loading 30 or so models taking 150ms, but the queries only take about 10ms total. This is on the dev server, with mysql running on the same machine.

Try the Django Debug Toolbar to see if it's like a middleware or something else that is slowing stuff down.

No Safe Word
Feb 26, 2005

zycl0n posted:

EDIT: It appears that after a bit more reading, I was beating my head against the wall. Going with mod_wsgi.
Ding ding ding. This is the correct choice.

http://docs.djangoproject.com/en/dev/howto/deployment/ posted:

If you’re new to deploying Django and/or Python, we’d recommend you try mod_wsgi first. In most cases it’ll be the easiest, fastest, and most stable deployment choice.

mod_python is kind of a pain in the rear end, to be quite honest

No Safe Word
Feb 26, 2005

nbv4 posted:

Is django-tagging still the best tagging extension? A google search brings up a lot of blogs that would assume it still is, but the latest official version doesn't even support 1.0.

Works pretty well for me, and it has a nice tag cloud template tag that it comes with that works well for my needs :)

No Safe Word
Feb 26, 2005

nbv4 posted:

hoooooly balls that worked. I had no idea defautl=0 was causing that. Thanks.

Well, I bet if you went to the trouble of changing "unknown" and "not hiring" to the "------" entries on each of those drop-downs it would work too. It sees a partially completed entry and assumes you intended to complete it so it's letting you know which fields in those partially completed entries need to be filled in to complete them.

No Safe Word
Feb 26, 2005

Ferg posted:

Anal retentive question: what editors support the syntax highlighting for an HTML view with the {% %} tags? I'm using PyDev currently, though I only defaulted to that because I use Eclipse so much at work. I'm open to other editors if Eclipse can't handle that syntax.

vim supports the django template syntax

No Safe Word
Feb 26, 2005

Magicmat posted:

How is Windows development support for Django, and Python in general? I'm talking about how well the actual interpreter works, as well as support tools like the version control system of choice for the Django community, and especially IDEs and/or editors. This is just for development; deployment would still be on the usual Linux stack.

I was trying to get back into Rails, but my response to asking the same question of them was "good luck; get a Mac." The Ruby interpreter is slow on Windows; the VCS of the Rails community is Git, which barely works on Windows and certainly not as well as SVN or Hg; and the editor of choice for Rails, Text Mate, is OS X only.

I'm getting tired of feeling like a second class citizen. Is Django development viable on windows? Or will I be locked out of some tools and using poor ports of others?

As a corollary, what is the IDE of choice for Django? Or even just the best code editor? (And don't say Vim or Emacs.)
I've tried getting eclipse with pydev working, but I'll be damned if I don't just go back to vim. I do a fair share of development on Windows, and it works fine for me.

edit: Catching this before the edit:

king_kilr posted:

Django (as well as Python) is fully supported on Python.
:downsowned:

No Safe Word fucked around with this message at 05:13 on Jul 6, 2009

No Safe Word
Feb 26, 2005

duck monster posted:

It works great. I use Eclipse with PyDev and it works fantastic.

There are also python plugins for Netbeans and Visual Studio.

Python is a microsoft anointed first class citizen on the Windows platform.

Ehhh.. IronPython is, which is generally up to date with CPython, but not 100%. For most uses it's up to date. The latest stable release brings it up to full Python 2.5 support but there's a beta that supports 2.6 and I've heard that it's pretty stable as well.

No Safe Word
Feb 26, 2005

Hanpan posted:

I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible.

It seems to me the best way to do this would be to create a custom field type, so I could do something like this in my model:

image_tb = models.CustomImageField("Thumbnail Image", upload_to ='uploads/projects', size=(50, 50), compression="60", watermark="path/to/watermark.png")

Firstly, I have absolutely no idea if this is the best way of doing things. Is it easier to create a custom field or perhaps hijack the save method? If it is the best method, does anyone have any really simple examples of creating a custom field? Most of the stuff online is incredibly complicated.

Secondly, if I was to create a custom field, is there a way to extend ImageField so I don't have to mess with the admin panel code and keep the core functionality in place?

Would really appreciate any help.
Yes, there is, and while I don't know of anything specifically to do what you want, there are all sorts of image-related snippets that are probably either what you want or "close enough" to borrow from:

http://www.djangosnippets.org/tags/image/

No Safe Word
Feb 26, 2005

Pie Colony posted:

I have a custom tag {% vote "292" %} or whatever. Basically inside the code for the tag it checks whether the ID (292) meets some criteria. If it does, I want it to render x template, if it doesn't, I want it to render y.

I'm having trouble with the rendering part. I have this as my test code right now:
code:
def render(self, context):
		return render_to_response('vote/vote_detail.html', {}, context_instance=context)
The problem is on my normal page, this adds a line "Content-Type: text/html; charset=utf-8" before the actual vote_detail.html. How do I get rid of this?

render_to_response returns an HttpResponse, if I recall correctly, custom template tags should just return a string. If you want it to basically load a template and render that then you'll have to create a Template with that path and call .render() and return that. Something like:

code:
def render(self, context):
   t = Template('vote/vote_detail.html', {})
   return t.render(context)
e: warning, untested code :siren:

No Safe Word fucked around with this message at 20:08 on Sep 23, 2009

No Safe Word
Feb 26, 2005

Stabby McDamage posted:

Also, is there a Django app repository or index? I didn't see one in the OP, and this site basically says "search google code, some random forum, or use something these guys wrote". Perl has CPAN and Python as PyPI, but is there a central repository for Django apps? Maybe PyPI is the answer?

Normally I would recommend Django Pluggables but it seems to be down at the moment!

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

Yup, can't use column aliases from the SELECT portion in the WHERE clause.

http://old.nabble.com/Column-alias-in-where-clause--td18967124.html

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