How do you approach unit testing for pluggable apps?

2015-12-21 Thread Nan
So far I usually just build a sample project that also serves as a demonstration of how to use the pluggable app, and use `manage.py test` to run the tests inside the pluggable apps test module. Is this the preferred method? Should a pluggable app's tests stand alone and be runnable outside

Best Way to Organize Project With Overlapping Functionality

2015-08-09 Thread Nan
? Thanks! Nan -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to dj

Re: Generic Relation in Legacy Database?

2015-03-10 Thread Nan
at 1:07:56 PM UTC-4, Avraham Serour wrote: > > use inspectdb to start > > On Sun, Mar 8, 2015 at 5:31 PM, Nan <ring...@gmail.com > > wrote: > >> >> Hi folks -- >> >> I'm building out Django models to represent a legacy PHP app's database &

Generic Relation in Legacy Database?

2015-03-08 Thread Nan
Hi folks -- I'm building out Django models to represent a legacy PHP app's database in order to throw together a quick admin panel. Everything's working great except that the ORM of the other application represents generic relations slightly differently than Django's does. I can't modify

Re: Passing variables from a context processor to a template

2012-01-05 Thread Nan
Two things: 1) make sure the context processor is installed in your settings file. 2) context processors should return dicts. Try: def swiss_context_processors(request): added_context = { 'mytest': 'aaa', } return added_context On Jan 5, 12:03 pm, Guy Nesher

Re: Help me with this query

2011-12-23 Thread Nan
Try Python's slicing syntax. [1] [1] https://docs.djangoproject.com/en/dev/topics/db/queries/#limiting-querysets On Dec 23, 2:16 pm, Babatunde Akinyanmi wrote: > Hello, > How can I get the ORM to do the equivalent of this sql query with the > result being a QuerySet: > >

Re: Redirect from get_queryset() in a class view?

2011-12-12 Thread Nan
I'm not sure, not having explored CBVs yet, but yes, I suspect you'll want to either decorate or override the method that usually returns the HttpResponse. On Dec 12, 1:50 pm, Eli Criffield wrote: > I like the raise exception idea, but where do i catch it? > In a

Re: Redirect from get_queryset() in a class view?

2011-12-12 Thread Nan
I'd recommend against doing that, as it's a strong violation of MVC principles. Instead you should either catch the ModelName.DoesNotExist exception in a custom (or inherited, or generic- view-wrapping) view, or raise a custom exception in your get_queryset method and catch that exception

Re: Django E-Commerce Framework

2011-12-08 Thread Nan
> I'm guessing that the OP wanted to develop a "standard" e-commerce > site for a single company, in which case I agree with Stuart and Andre > that the way to go is a well-tested e-commerce framework. > > I had to roll my own because I was doing something very different > ... > But had a >

Re: Template filter with multiple non-string arguments?

2011-12-06 Thread Nan
fancy template tag to update the context -- although that seems like overkill. Does the ticket [1] relating to this need a design decision or just a patch? [1] https://code.djangoproject.com/ticket/1199 On Dec 6, 7:49 am, Reinout van Rees <rein...@vanrees.org> wrote: > On 06-12-11 02:05,

Template filter with multiple non-string arguments?

2011-12-05 Thread Nan
So, yes, I know one can combine template filter arguments by quoting them into a single concatenated string... But what if one needs to do something that amounts to the following? {% for object in object_list %} {{ some_other_var|custom_filter(constant_string, object.field)|

Re: add project directory path to python path permanently

2011-12-01 Thread Nan
Do you have pip installed? If so, you can just create a setup.py script [1] and from inside your project directory run: pip install -e ./ I assume setuptools (easy_install) can do the same, but I'm not 100% clear on the command. [1] http://docs.python.org/distutils/setupscript.html On Dec

Re: A view associated with a lot of urls

2011-11-29 Thread Nan
Django's regular-expression based URL dispatcher is designed to do this directly; and you might want to use a model (database table) for each of your lookups. The third part of the tutorial [1] addresses this. [1] https://docs.djangoproject.com/en/dev/intro/tutorial03/ On Nov 29, 3:30 am,

Re: Large Queryset Calculation In Background?

2011-11-28 Thread Nan
On Nov 28, 10:17 am, Javier Guerra Giraldez wrote: > On Mon, Nov 28, 2011 at 10:10 AM, Tom Evans wrote: > > Django currently always fetches the entire result all at once, > > regardless of how you then fetch the data from the queryset. Ah, I must

Re: Large Queryset Calculation In Background?

2011-11-28 Thread Nan
We're using MySQL 5 (don't know off the top of my head what specific release). I don't think a master/slave DB configuration is something we can manage to set up at this point. Querysets are fetched from the database in chunks, right? I imagine that the select itself is actually quite quick,

Re: Large Queryset Calculation In Background?

2011-11-23 Thread Nan
Thanks, Tim -- that looks handy too. Can anyone comment on the database locking question? On Nov 22, 10:16 pm, Tim Chase wrote: > On 11/22/11 17:04, Nikolas Stevenson-Molnar wrote: > > > I wouldn't expect it to lock the database (though someone with more > >

Re: Large Queryset Calculation In Background?

2011-11-22 Thread Nan
xpect it to consume > > significant CPU. If you're on UNIX, you could address this issue by making > > your process 'nice':http://docs.python.org/library/os.html#os.niceThe > > nicer a process (higher the value), the less CPU it will hog. IIRC, nice > > values default to 0

Large Queryset Calculation In Background?

2011-11-22 Thread Nan
for a while or eat tons of CPU? Any suggestions? I'm using Django 1.2, btw. Thanks, -Nan -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this g

Re: Automatically direct unauthenticated users to homepage

2011-11-15 Thread Nan
If this is going to be the case for every single view on your site (i.e. there are no exceptions for help pages or forgotten password views or such), you could probably do it with a custom middleware. But @login_required is probably the best way to go, yeah. On Nov 15, 11:16 am, CrabbyPete

Re: Serve a subset of uploaded media via Django

2011-11-11 Thread Nan
if any other complications arise. [1] http://stackoverflow.com/questions/1729051/django-upload-to-outside-of-media-root [2] https://github.com/johnsensible/django-sendfile On Nov 11, 11:38 am, Andre Terra <andrete...@gmail.com> wrote: > Hello, Nan > > Please read through the Fi

Serve a subset of uploaded media via Django

2011-11-11 Thread Nan
to accomplish this without twisting myself in knots? FWIW, this project is being hosted in multiple different server environments, from nginx + apache/mod_wsgi to FCGI to lighttpd. Thanks, -Nan -- You received this message because you are subscribed to the Google Groups "Django users" grou

Re: Multiple sessions per user?

2011-11-07 Thread Nan
on it) and a custom request.sessions list with all sessions. Does anyone see any major pitfalls to this approach? Thanks, -Nan On Nov 4, 2:32 pm, Nan <ringe...@gmail.com> wrote: > OK, the subject doesn't *quite* describe what I need to do, but > almost.  Basically, I'd like to have > &g

Multiple sessions per user?

2011-11-04 Thread Nan
OK, the subject doesn't *quite* describe what I need to do, but almost. Basically, I'd like to have 1) one "session" that expires after logout or browser close, and applies to logged-in sessions (like the default Django session framework using the "SESSION_EXPIRE_AT_BROWSER_CLOSE" setting) 2)

Re: Possible to run manage.py sqlall [appname] without db connection?

2011-10-27 Thread Nan
Probably because due to quirks of each DB engine, the SQL differs depending on your DB connection info. On Oct 26, 6:18 pm, Jason wrote: > I need to be able to output the table creation code but I don't > necessarily have access to a database. > > Why does simply outputting

Re: Weird situation about static file

2011-10-27 Thread Nan
You may need to run manage.py collectstatic again, unless you used collectstatic -l when you first collected your static files. On Oct 26, 12:22 pm, Tsung-Hsien wrote: > I just change some style of css, but after runserver, the css is > nothing change. > I not only

Re: When is it useful to run multiple admin sites?

2011-09-11 Thread Nan
I've done this for a multitenant project where we wanted each tenant to have their own admin site with just their own data filtered, as well as a central admin where senior staff could manage all tenants' data. It's also handy if you want different interfaces (custom forms, read-only or excluded

Re: Initial data for ManyToMany field

2011-09-06 Thread Nan
Because SymptomeForm is a ModelForm, it will initialize its "parent" field as a ModelMultipleChoiceField, which I believe must be initialized with a queryset instead of a list. On Sep 6, 4:30 pm, Thomas49 wrote: > Hello, > > I have two models, and the second

Re: Displaying information as a table?

2011-09-03 Thread Nan
There's a django-tables app[1], and a more actively maintained (AFAICT) django-tables2[2]. [1] https://github.com/miracle2k/django-tables [2] https://github.com/bradleyayers/django-tables2 On Sep 3, 12:02 pm, Levi Campbell wrote: > In a django template, what's the best

Re: django-sms-gateway

2011-08-31 Thread Nan
__init.py__ (incorrect) or __init__.py (correct)? I suspect you'll need to a) describe in more detail what you're trying to do and what's failing, and b) share more of your code and the error traceback in order for anyone to help you diagnose the problem. On Aug 31, 4:28 am, damola oyeniyi

Re: Argh: templates, admin, and app loading order

2011-08-31 Thread Nan
Hm, yes, that might work, although at this point I'm a little concerned about changing the order of applications anyway, since I'm not sure what other side effects it might have. Mostly I'm uncomfortable with how important application order ends up being to how one's project operates, especially

Argh: templates, admin, and app loading order

2011-08-30 Thread Nan
ny. Now, I know how to work around this: create a separate app for admin overrides that loads at the end of the INSTALLED_APPS list instead of the beginning. But am I the only one who thinks that feels a little clumsy? Thoughts? Other solutions? Thanks, -Nan -- You received this message becaus

Re: "app_index.html" = i want to be in admin...

2011-08-19 Thread Nan
> where should i change https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance > and where to put this file..? https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types -- You received this message because you are subscribed to the Google Groups "Django

Re: M2M with self throught int. table, how to access related items?

2011-08-16 Thread Nan
> For example, given a post, how to get set of posts which have traffic from > the post (post.tfrom_set ? ) Have you tried: class Post(models.Model): ... def posts_with_traffic_from_here(self): return Post.objects.filter(tto__tfrom=self) > how to get post with a max "count" which is

Re: search with a optional value

2011-08-16 Thread Nan
Filters can be applied in multiple statements, and querysets are evaluated lazily, so the following would work and would only run a single query, when you finally output or otherwise check the contents of the results variable: def get_results(...): ... results =

(Solved) Re: Admin inlines suddenly missing?

2011-08-15 Thread Nan
User error (ish). Some data updates we'd made directly to the database had resulted in an invalid foreign key. Lesson learned: don't use MyISAM unless absolutely necessary. On Aug 15, 5:11 pm, Nan <ringe...@gmail.com> wrote: > Further investigation indicates that the templa

Re: Admin inlines suddenly missing?

2011-08-15 Thread Nan
of inline_admin_formset.opts.template (admin/ edit_inline/tabular.html) and that the file exists and has global read permissions. Does that help at all with the diagnosis? On Aug 15, 11:52 am, Nan <ringe...@gmail.com> wrote: > Yes, the ModelAdmins are declared in a separate admin.py.  Just tried >

Re: Admin inlines suddenly missing?

2011-08-15 Thread Nan
to the browser the ModelFormSet throws a ValidationError: [u'ManagementForm data is missing or has been tampered with'] when we try to save the Ticket.) Thanks for your suggestions! On Aug 15, 11:29 am, Reinout van Rees <rein...@vanrees.org> wrote: > On 15-08-11 16:18, Nan wrote: > &g

Admin inlines suddenly missing?

2011-08-15 Thread Nan
was fine. Below are the (simplified) models and admins. Since I can't reproduce the problem in staging, can anyone suggest where to start in terms of tracking down what's going wrong without disrupting production? Thanks! Nan ### models.py class Zone(models.Model): name = models.CharField

Re: Issues with ManyToManyField

2011-07-19 Thread Nan
Try unique_together on employee and team in the TeamMember model -- it will throw an error if you try to add a record with the same employee and team as another. On Jul 19, 7:27 pm, Felipe Spychalski wrote: > Hello, > > I'm having an issue with my schema and the admin

Re: defining model with list of foreign keys?

2011-07-19 Thread Nan
Try a ManyToManyField, which essentially creates the article_devices table but abstracts it away so you don't have to think about it. On Jul 19, 7:52 pm, Alex Hall wrote: > Hello all, > I am trying to figure out the best way to represent a field in a > model. The model is an

Re: Weird Django "caching" problem

2011-07-16 Thread Nan
If clearing your browser cache fixes it, then it's browser caching, not Django caching. It's possible your PHP site was sending cache suppression headers. If you want to prevent browser and proxy caching, look into Django's never_cache decorator. On Jul 16, 9:51 am, Nathan Hoad

Re: filter cache output

2011-07-15 Thread Nan
Well, you can use one of the methods from [2] to force the queryset to evaluate before caching it. But you'll still run a new query in order to filter, unless you aftually filter the data in your Python code. On Jul 15, 2:46 pm, Rob <robvan...@zonnet.nl> wrote: > On Jul 15, 8:34 pm, N

Re: filter cache output

2011-07-15 Thread Nan
Querysets are evaluated lazily.[1][2] You may have better success using template fragment caching[3] to cache the menu output. [1] https://docs.djangoproject.com/en/dev/topics/db/queries/#querysets-are-lazy [3]

Re: Newbie question, I'm having difficulty getting the admin panel to work!

2011-06-24 Thread Nan
The sporadicness may have to do with the way it's being served -- that happens to me when running via FCGI if I save a change but don't restart the process. Depending on your server setup, that may mean touching the WSGI file or touching another special file or restarting your Apache process or

Re: Errors saving blank Admin Inline with FilePathField?

2011-06-23 Thread Nan
= [('','--'),] + self.fields['some_fpath_field'].choices class MyInline(models.TabularInline): form = MyAdminForm On Jun 23, 10:43 am, Nan <ringe...@gmail.com> wrote: > This is driving me batty... > > Because there's no blank option in the form field for a FilePathField > with blank=

Errors saving blank Admin Inline with FilePathField?

2011-06-23 Thread Nan
because the FilePathField is not blank but the other fields are, and so the formset thinks you're trying to save those objects but have left the other required fields blank. Is there *any* workaround for this? Thanks, -Nan -- You received this message because you are subscribed to the Google

Re: Unit-Testing Dilemma

2011-06-22 Thread Nan
> Use Mock and assert_called_with: > http://www.voidspace.org.uk/python/mock/mock.html#mock.Mock.assert_ca... > In this case you'd set theAPI.call as your mock and check that under > different conditions it is called correctly. Oh, perfect -- thank you, that will help a lot! > You don't need

Re: Unit-Testing Dilemma

2011-06-21 Thread Nan
> That's what I was suggesting; that way the view becomes simple enough that > anyone looking at it can be assured of its correctness, without a host of > unit tests. Those tests can be applied to the functions that actually > construct the messages. Right, it's really those supporting

Re: Unit-Testing Dilemma

2011-06-21 Thread Nan
> Your view function may indeed be too complex to test properly, and it sounds > like it is too tightly coupled with with the API call -- there is no way to > call the view without having it call the actual 3rd-party API as imported at > the top of the file. I'd be a little confused as to how

Re: Unit-Testing Dilemma

2011-06-20 Thread Nan
n Mon, Jun 20, 2011 at 3:52 PM, Nan <ringe...@gmail.com> wrote: > > I'm not testing the third-party service.  I need to test *what I send > > to them*.  I.e. that the output of my_view is correct.  The trouble is > > that neither my_view nor the API call actually returns the

Re: Unit-Testing Dilemma

2011-06-20 Thread Nan
dan...@roseman.org.uk> wrote: > On Monday, June 20, 2011 6:07:59 PM UTC+1, Nan wrote: > > > In most situations, my app, upon receiving an HTTP request, sends data > > to a third-party API, and returns an empty HttpResponse.  I need to > > test that the correct data is sen

Unit-Testing Dilemma

2011-06-20 Thread Nan
In most situations, my app, upon receiving an HTTP request, sends data to a third-party API, and returns an empty HttpResponse. I need to test that the correct data is sent to the third-party API based on internal application state. I'm perplexed as to how to intercept this data in a unit test.

Re: sorl thumbnail

2011-06-10 Thread Nan
I encountered that error at one point when upgrading Sorl Thumbnail versions. Can't remember exactly how I worked around it, but it had something to do with clearing out caches. There are data caches that you can clear with Sorl's custom management commands and disk caches that you can delete.

Re: Django daemon

2011-06-09 Thread Nan
Wait... how long has django.utils.daemonize existed, and why isn't it documented? (Wishing I'd known about this 12 months ago...) On Jun 9, 8:19 am, Tom Evans wrote: > On Thu, Jun 9, 2011 at 12:50 PM, Sherif Shehab Aldin > > wrote: > > Actually

Re: VERY cheap django hosting?

2011-06-08 Thread Nan
Seconding the suggestion of asmallorange.com -- one of the best inexpensive hosts I've used. I haven't run Django on their servers, but it can be made to run using FastCGI (there are instructions on their wiki somewhere). On Jun 8, 2:30 am, raj wrote: > Hey guys, > Just

Re: best framework/reusable app for caching model instances (object level cache) ?

2011-06-08 Thread Nan
I'm looking into caching options at the moment too. Did you end up using django-cache-utils? Is it working out for you? On May 17, 12:36 pm, stargazer wrote: > After looking at these libraries... I think the best solution would be > not use these kind of libraries

Workaround for #13167?

2011-06-06 Thread Nan
Hi folks -- I'm having a problem with TemplateSyntaxErrors in Django 1.2 because a third-party app's views aren't setting a variable that gets used in filters (see [1]). I can't set the variable in a context processor because I don't want to override it in places where I'm setting it explicitly.

Re: mod_wsgi on cPanel/WHM gets easier

2011-06-02 Thread Nan
Man, wish I had something like that a couple years ago. Please keep us posted on further developments! On Jun 1, 12:08 pm, shacker wrote: > If you run a cPanel/WHM server, and have manually compiled mod_wsgi in > the past, you know that updating apache/php for the rest

Re: Weird Error when following django book?

2011-05-25 Thread Nan
The "u" before the opening quote is Python's way of telling you that it's a Unicode string instead of an ASCII string. On May 25, 11:54 am, raj wrote: > I'm up to the html template part of the djangobook, and I keep getting > a weird output error whenever I do a t.render()

Re: UK-based Django Host?

2011-05-25 Thread Nan
<daniel.hil...@gmail.com> wrote: > On 25 May 2011 14:43, Nan <ringe...@gmail.com> wrote: > > > > > Thanks for the suggestions, guys.  I've heard great things about > > Linode, but we really need managed hosting. > > Then have a look at Rackspace cloud mana

Re: UK-based Django Host?

2011-05-25 Thread Nan
Thanks for the suggestions, guys. I've heard great things about Linode, but we really need managed hosting. On May 25, 7:24 am, Simon Connah <simon.connah...@gmail.com> wrote: > On 24 May 2011, at 18:03, Nan wrote: > > > I know this question has been asked before, but the

Re: UK-based Django Host?

2011-05-24 Thread Nan
t;m...@shofty.me> wrote: > just use webfaction, you dont know that they're US when you connect > from the UK, speed isnt an issue. > I moved to a VPS for cost reasons, but webfaction were fine for me. > > Matt > > On May 24, 6:03 pm, Nan <ringe...@gmail.com> wrote: > > >

UK-based Django Host?

2011-05-24 Thread Nan
ideally be (like Webfaction) fully managed. (We don't have the staff to keep a server updated or tuned). We need plenty of memory, shell access (of course), and preferably mod_wsgi. Does anyone have any recommendations of hosts they've worked with? Thanks! -Nan -- You received this message because

Re: Best django ecommerce aplication?

2011-05-19 Thread Nan
Wow, just in the few months since we settled on Satchmo for our store, the e-commerce ecosystem seems to have really exploded, and some of the alternatives matured significantly. It's awesome to see the growth, and I'm not sure we would have made the same decision now. On May 19, 9:31 am,

Re: Set ModelMultipleChoiceField selected in clean()?

2011-05-16 Thread Nan
Sorry, I should have clarified. I have been logging. I've logged pretty much every variable in every method. It's all there and properly set until it has to be retrieved from the next form in the wizard; and if there's an error in an unrelated field, the values do not show as selected in the

Set ModelMultipleChoiceField selected in clean()?

2011-05-16 Thread Nan
For a formwizard, I'm trying to set the values of a ModelMultipleChoiceField in the form's clean() method, based on the cleaned_data from another field, and it's not working. Here's roughly what I'm trying to do: # forms.py from django import forms from myapp.models import MyModel class

Re: Cache entire page *except* one block?

2011-05-13 Thread Nan
Ah, that helps a lot! Thanks, Jacob! On May 13, 5:22 pm, Jacob Kaplan-Moss <ja...@jacobian.org> wrote: > On Fri, May 13, 2011 at 3:01 PM, Nan <ringe...@gmail.com> wrote: > > I'm working on a site where about 95% of the pages are "static" and > > change

Cache entire page *except* one block?

2011-05-13 Thread Nan
e to be re-rendered, and b) that would mean updating every one of about 30 views, and any views built in the future, which doesn't feel very DRY or maintainable. Am I missing something, or misunderstanding something fundamental about how Django's cache framework works? Thanks! -Nan -- Yo

Re: DecimalFields, Floats, and Strings?

2011-05-11 Thread Nan
? On May 11, 3:11 pm, Shawn Milochik <sh...@milochik.com> wrote: > On 05/11/2011 03:01 PM, Nan wrote: > > > Using Django 1.2.3, I recently declared a DecimalField on a model, and > > it happily accepts a float as its default value, but it won't filter > > on a float

DecimalFields, Floats, and Strings?

2011-05-11 Thread Nan
Using Django 1.2.3, I recently declared a DecimalField on a model, and it happily accepts a float as its default value, but it won't filter on a float (it throws a TypeError instead). Is there a reason for this inconsistency? -- You received this message because you are subscribed to the Google

Re: Strange admin changelist bug with list_editable and FK to User in 1.2.3

2011-03-31 Thread Nan
Ah, that does look like it could be the same thing. Thank you! The ticket suggests it was backported, so I'll try upgrading to 1.2.5. On Mar 31, 7:41 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Thu, Mar 31, 2011 at 3:35 PM, Nan <ringe...@gmail.com> wrote: > > Any ide

Strange admin changelist bug with list_editable and FK to User in 1.2.3

2011-03-31 Thread Nan
Hi folks... I've got a model that looks roughly like so: class Account(admin.ModelAdmin): type = models.ForeignKey(AccountType, help_text='Type of account. Determines what features are available to the user.') user = models.ForeignKey(User, unique=True, primary_key=True) design =

Re: When would you use Context instead of RequestContext?

2009-10-14 Thread Nan
So it's basically just an issue of optimization? Is using RequestContext best practice for apps meant to be pluggable? On Oct 14, 1:25 pm, justquick wrote: > it helps performance slightly since it does not include the request > itself or any of the other goodies in

Re: Apply decorator to view functions in third-party apps?

2009-10-13 Thread Nan
As an aside, it seems curious to me that in a generally flexible framework like Django a problem like this should have only a dirty solution. I've encountered a few instances where it would be useful to have access to request variables, but there's no way to pass them. On Oct 13, 3:10 pm,

Re: Apply decorator to view functions in third-party apps?

2009-10-13 Thread Nan
<mihail.lu...@googlemail.com> wrote: > Seems that any solution would be dirty, so why don't you set threadlocal > variable with request and monkey-patch template loader? > > > > On Tue, Oct 13, 2009 at 11:03 PM, Nan <ringe...@gmail.com> wrote: > > > The trouble is t

Re: Apply decorator to view functions in third-party apps?

2009-10-13 Thread Nan
True. I'd like to find a solution with as few places as possible to maintain changes, though. > Even if you patch django and add request argument to get_template you > also should rewrite all aplication views to push their requests into > get_template. > > It's quite simple to only patch views

Re: Apply decorator to view functions in third-party apps?

2009-10-13 Thread Nan
The trouble is that I've got third-party apps that have their own views that don't include the template logic. so in thirdpartymodule.views.py: def thirdpartyview(request, vars): # Do lots of fancy processing return render_to_response('template.html', context) In my project, I need a

Re: new permission

2009-10-13 Thread Nan
Try deleting the table for the model in whose Meta class you're defining the permission. I believe permissions are added only when the table for the model they're defined in is created. On Oct 13, 5:08 am, elminio wrote: > hi, > > It didnt help :/ > > On Oct 9, 10:33

Re: Apply decorator to view functions in third-party apps?

2009-10-13 Thread Nan
h function in the module but it also will have > no information about HttpRequest... > > All I can see here is trying to decorate view with decorator setting global > variable in that views module to current request. Then decorating function > get_template to pick this global variab

Re: Apply decorator to view functions in third-party apps?

2009-10-12 Thread Nan
Well, I'm using a theming system -- each user can choose a theme to use, and that choice is attached to their account. Not just the base template but the inner templates for some parts of the site can vary from theme to theme, so I want to run something to the following effect: def

Re: Getting former value of altered field when saving model

2009-10-07 Thread Nan
It should work in pre_save, but by the time you reach post_save, the database ID will be associated with the new values. On Oct 7, 1:32 pm, Aaron <aa...@genieknows.com> wrote: > On Oct 7, 2:14 pm, Nan <ringe...@gmail.com> wrote: > > > class Foo(models.Model): > >

Re: Getting former value of altered field when saving model

2009-10-07 Thread Nan
class Foo(models.Model): bar = models.IntegerField() def save(self, force_insert=False, force_update=False): if self.id: # this is an update rather than a new instance old = Foo.objects.get(pk=self.id) # DO STUFF super(Foo,

Re: How do I create project independent apps.

2009-10-05 Thread Nan
You can move your apps outside your project to somewhere on your python path. So for instance, move the directory from some-path/ mysite/myapp to some-path/myapp . Then install it as "myapp" instead of "mysite.myapp" and change your imports to "from myapp.models" (etc) instead of "from

Re: Run a filter on path in {% extends %} tag?

2009-10-05 Thread Nan
That still requires either the view or context processor to somehow know which layout each inner template extends (the 1-column version? the 3-column version? etc.), which is something I'd prefer the inner template to know. On Oct 4, 6:42 pm, Kristaps Kūlis wrote: >

Re: Populating an ImageField

2009-10-03 Thread Nan
Thanks. For a simpler case than what I'm dealing with, yes, that would probably work. On Oct 3, 2:21 pm, kmike <kmik...@googlemail.com> wrote: > If you have one default logo then maybe the 'right' way is to use > 'default' parameter of ImageField? > > On 3 окт, 22:07, Nan &

Re: How to change name for model in Admin?

2009-10-03 Thread Nan
Yes. class Foo(models.Model): # field definitions here class Meta: verbose_name = 'Bar' See also: http://docs.djangoproject.com/en/dev/ref/models/options/#ref-models-options On Oct 3, 10:37 am, adelaide_mike wrote: > Hi again. > I have made a

Re: Populating an ImageField

2009-10-03 Thread Nan
(logo_path) company.logo = File(logo_file) company.save() On Oct 2, 10:15 pm, akonsu <ako...@gmail.com> wrote: > did you try > > company.logo = relative_path > > ? > > On Oct 2, 4:45 pm, Nan <ringe...@gmail.com> wrote: > > > OK, this seemed

Re: Populating an ImageField

2009-10-02 Thread Nan
OK, this seemed to work: def create_a_company(name, logo_path): company = Company() company.name = name relative_path = path_relative_to_media_root(logo_path) company.logo.name = relative_path company.save() Thank you! On Oct 2, 4:32 pm, Nan <ringe...@gmail.com>

Re: Populating an ImageField

2009-10-02 Thread Nan
I tried this, but it's just throwing an AttributeError ("can't set sttribute"): def create_a_company(name, logo_path): company = Company() company.name = name logo_url = image_url_from_path(logo_path) company.logo.url = logo_url company.save() On Oct 2, 4:15 pm, akonsu

Re: Queryset.delete() - docs missing?

2009-09-30 Thread Nan
That's a good reason. If I get some time, I'll give it a shot. On Sep 30, 5:58 pm, Daniel Roseman wrote: > On Sep 30, 9:17 pm, ringemup wrote: > > > From [1]: > > > "You can also delete objects in bulk. Every QuerySet has a delete() > > method,

Re: create a method that only one user can access in the same time

2009-09-29 Thread Nan
Any particular reason you can't just use User.objects.count() ? On Sep 29, 7:16 pm, gustavo Cardoso wrote: > Hello Folks, > > I need to implement a Counter. > One variable to store the number of users in my site. > This variable can't be access in the same time for more

Re: Subclassing a model to change field attributes?

2009-09-29 Thread Nan
You're right, it could be done in form validation. I'm not sure why I feel compelled to validate everything at the model (or DB) level. On Sep 29, 3:28 pm, Daniel Roseman wrote: > On Sep 29, 6:53 pm, ringemup wrote: > > > I have two models that are

Re: Modeling and validating international addresses?

2009-09-27 Thread Nan
Google finds one app that seems pretty heavyweight (and poorly documented): http://code.google.com/p/django-global-contact/ At first glance, building a model that can read address formats from a database for forms and output should be fairly straightforward, but input validation is much more

Re: Overriding verbose_name in contrib or 3rd-party apps?

2009-09-27 Thread Nan
Thanks for the suggestions, everyone. It seems to be popping up for all sorts of things -- from changing verbose_name in order to globally relabel form fields in ModelForms to changing __unicode__ methods to change template output. I know there are workarounds, but they seem less DRY. On Sep