Maintain server-initiated FTP connection between client requests?

2011-12-28 Thread Jordon Wing
Hey,
I'm going to use ftplib to open up an FTP connection to an FTP server 
provided by the user.  The client will be sending FTP commands to my django 
server via Ajax, which will then be forwarded to the FTP server the user 
provided. However, I'd like to not have to create a new FTP server 
connection every time the client sends an FTP command. In other words, I 
want to keep the FTP connection alive between requests by the client.

How would I do this? Would some sort of comet implementation be best? I was 
initially planning to use WebSockets until I discovered my host won't allow 
it. =\

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Rl3fOeaZsQcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: reverse() is not working.

2011-12-28 Thread Daniel Roseman
On Wednesday, 28 December 2011 18:43:06 UTC, Nirmal Kumar wrote:
>
> I am trying to pass the id to thanks view through reverse. But it's not 
> working. I'm getting this error 
>
> Reverse for 'reg.views.thanks' with arguments '(20,)' and keyword 
> arguments '{}' not found. 
>
> I posted the question with the code in stackoverflow: 
>
> http://stackoverflow.com/questions/8648196/reverse-is-not-working 
>
> How can I transfer arguments from one function to another in views?. Is it 
> a normal thing or I have to use any built in functions? 
>
> Thanks.


Your question is answered correctly at StackOverflow (not by me, for a 
change, but by moguzalp). If that's not working, you'll need to update that 
question with exactly what your view and urls.py look like now after 
following the advice in that answer.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/LCpn535gdKEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django - Forms Widget TypeChoiceField - how to set id for two radio buttons

2011-12-28 Thread luke lukes
@ Mengu, Timothy Makobu: tnx for your replies.
this is the custom renderer class: pastebin.com/9x8HPgT1 but
honestly i have not understand where to modify the code since it's
just a code snippet found on the internet.
I also tried to modify the usertype parameter in the form, passing
with it the two attrs dictionaries (since i need two different ids and
name for each radiobutton) but it didnt worked...any help?



On 27 Dic, 08:39, Timothy Makobu  wrote:
> Try this:
>
> widget=forms.RadioSelect(renderer=HorizRadioRenderer,
> attrs={"id":"whatever_you_want"})
>
>
>
>
>
>
>
> On Tue, Dec 27, 2011 at 3:08 AM, Mengu  wrote:
> > hi luke,
>
> > instead of setting auto_id to False, you should give it a string
> > parameter. please read more on
>
> >https://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api-co...
> > .
>
> > all the best.
>
> > On 26 Aralık, 21:45, luke lukes  wrote:
> > > hi everyone. i'm using a form with a TypeChoiceField, this is the form
> > > code:http://pastebin.com/GHttrDyN. now i'm trying to set a custom id
> > > for the two radio buttons displayed but i havent found yet the right
> > > way. maybe it's possible set it during form instantiation (as i set
> > > auto_id=False) in the view, but it's just my assumption, anyway i
> > > haven't find anything helpful on the internet.any idea?
>
> > > thanx - luke
>
> > --
> > 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 group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django-deeper

2011-12-28 Thread Justin Holmes
In response to the recent discussion of SOPA on the django-dev list
(and to the recurring phenomenon of having no clearly defined space to
congregate to discuss "deeper" issues), I have started a new google
group, django-deeper.

As a relative newcomer to the django community, I have been
overwhelmed by the awesome vibes.  Djangocon 2011 was one of the best
conferences (probably top 5 even) that I've ever been to.

>From the very first peek at the project, it's clear that django has a
much sharper focus on community building than is typical for a
software project.  The emphasis and effort on documentation, for
example, sends a strong signal that "this is not just a piece of
software, it's a group of passionate people."  The mature and
open-minded atmosphere of the django IRC presence also suggests this.

As the django community expands in breadth and in depth, we need a way
to ensure that our underlying aspirations - expressed sometimes in the
form of python code but sometimes as political, philosophical, or
psychological prose, are likewise cultivated.  My hope is that
django-deeper will provide a forum for those of us who welcome growth
in this direction.

http://groups.google.com/group/django-deeper

-- 
Justin Holmes

Head Instructor, SlashRoot Collective
SlashRoot: Coffee House and Tech Dojo
60 Main Street
New Paltz, NY 12561
845.633.8330

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: YouTube Integration

2011-12-28 Thread Brian Neal
On Dec 28, 11:46 am, Hassan  wrote:
> Dear All,
>
> I want to know if there is a way that i can get youtube videos to my
> website using a video url ?
>
> Best Regards ,
>
> Hassan AL-Natour

Have you seen the oEmbed specification?
http://oembed.com/

I believe there is a Django application that incorporates this, but it
isn't hard to roll yourself either.

https://github.com/ericflo/django-oembed

Best,
BN

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



reverse() is not working.

2011-12-28 Thread Nirmal Kumar
I am trying to pass the id to thanks view through reverse. But it's not 
working. I'm getting this error 

Reverse for 'reg.views.thanks' with arguments '(20,)' and keyword arguments 
'{}' not found. 

I posted the question with the code in stackoverflow: 

http://stackoverflow.com/questions/8648196/reverse-is-not-working 

How can I transfer arguments from one function to another in views?. Is it 
a normal thing or I have to use any built in functions? 

Thanks. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VF5fUs-Z2-wJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



YouTube Integration

2011-12-28 Thread Hassan
Dear All,

I want to know if there is a way that i can get youtube videos to my
website using a video url ?

Best Regards ,

Hassan AL-Natour

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



CACHE_MIDDLEWARE_ANONYMOUS_ONLY isn't working for me

2011-12-28 Thread Brian Neal
I have CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True. It seems to cache pages
even for people who have logged in. For example, I can log into the
admin, and edit an object. If I then visit the view for that app, my
changes do not get seen until the 5 minute cache timeout hits.

I suspect my middleware order is not correct, but I have read and re-
read the docs and I'm still confused.

Here are my cache related settings:

CACHES = {
'default': {
'BACKEND':
'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT': 600,
},
}

CACHE_MIDDLEWARE_ALIAS = 'default'
CACHE_MIDDLEWARE_SECONDS = 600
CACHE_MIDDLEWARE_KEY_PREFIX = 'BNS'
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

MIDDLEWARE_CLASSES.insert(0,
'django.middleware.cache.UpdateCacheMiddleware')
MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware')

Does anyone see anything wrong or have suggestions on how to debug
this?

Thanks,
BN

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: All models with FKs, M2Ms, or 121s pointing to a given model

2011-12-28 Thread JohnA
It's maybe not as rigorous as the explicitly _meta-based approach
noted by Russ McGee, but I use straight introspection combined with a
knowledge of naming conventions, as follows:

# This function looks only at passed in object, not its derived
subobjects
# If you want items from the most derived class or whatever, get that
object first
# and then call this function on it.

def getRelatedManagerNamesAndObjects(object,namePrefix=None): #
returns a list of name-value pairs
if namePrefix == None:
namePrefix = ''
namesAndValues = []
for name in dir(object):
if not name.startswith(namePrefix):
continue
try:
value = getattr(object,name)
except:
continue
typeStr = str(type(value))
if typeStr.find('RelatedManager') != -1:
namesAndValues.append((name,value))
return namesAndValues

It doesn't find 121 relationships, only m21 (FK) and m2m, but that's
what I want to find.  I use a similar introspection method to find 121
relationships, which for me all result from multi-level multi-table
inheritance.  So far both methods have worked fine for me.  They may
seem a little inefficient but I don't do them that often and I assume
that the resources they use are nothing compared to the joins that are
needed to get the actual data I'm looking for (i.e. queries made on
the returned related managers).

-- John

On Dec 27, 9:01 pm, Daniel Kaplun  wrote:
> How do I get all models with FKs, M2Ms, or 121s pointing to a given
> model?
>
> I am using djcelery. I have a BakedModel with a FK to TaskMeta, which
> is the model that stores task status (I only care whether it is
> complete). I want to generate a query set that will return all
> instances of a given model where all deep references to and from the
> instance that are TaskMeta instances have status=SUCCESS. Currently, I
> am able to perform said operation for all relations from a given
> model, but the other way -- to a given 
> model.http://paste.pocoo.org/show/526681/

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Constraints on a one-to-many relationship and related problems

2011-12-28 Thread Jay De Lanoy
I'd go for a separate table instead, with something like

class BillingInfo(models.Model):
customer = models.OneToOneField(Customer)
billing_address = models.OneToOneField(Address)

and then just have logic in the views and templates to account for
existence/nonexistence of a given customer's billing address.

On Dec 28, 9:21 am, Dan Gentry  wrote:
> Just looking at the models, I'd like to make a couple of suggestions.
>
> Instead of using a Foreign Key relationship in Customer to indicate
> the billing address,  I would include a flag called 'billing_address'
> in the Address table that would be set to True for the customer
> selected address.
>
> An override of save() in the Address model is then used to enforce the
> 'only one billing address' rule.
>
>     def save(self):
>         ''' This will turn off the billing address flag for all other
> addresses for this customer if the new record is selected '''
>         if self.billing_address:
>             old_billing_address =
> Address.objects.filter(customer=self.customer).filter(billing_flag=
> True)
>             for s in old_billing_address:
>                 s.billing_flag = False
>                 s.save()
>         super(Address, self).save()
>
> Hope this helps,
>
> Dan
>
> On Dec 28, 6:02 am, Bart Nagel  wrote:
>
>
>
>
>
>
>
> > I'm new to Django. I'm finding it very impressive so far but have hit
> > a cluster of problems. I'm using the SVN version.
>
> > Sorry for the length of this, I'm just trying to explain as fully as I
> > can what I'm trying to do, what I have and what's going wrong.
>
> > The relevant parts of my model, in the simplest terms, look like this.
>
> >     from django.db import models
>
> >     class Address(models.Model):
> >         customer = models.ForeignKey("Customer")
> >         street = models.CharField(max_length=128)
> >         city = models.CharField(max_length=128)
>
> >         def __unicode__(self):
> >             return "%s, %s" % (self.street, self.city)
>
> >     class Customer(models.Model):
> >         last_name = models.CharField(blank=True, max_length=64)
> >         first_name = models.CharField(blank=True, max_length=64)
> >         billing_address = models.ForeignKey("Address", related_name="+")
>
> >         def __unicode__(self):
> >             return "%s %s" % (self.first_name, self.last_name)
>
> > So customers can have many addresses, and one of those addresses is
> > pointed to by the customer as being the billing address.
>
> > I then have the Customer admin page set up so that Address entries are
> > edited inline on the same form.
>
> > 1. The billing address should be required, but obviously when it's a
> >    new Customer there won't be any addresses on file, so there will be
> >    no choices on the billing address dropdown.
>
> >    So I need a way to accept a blank selection for billing address,
> >    maybe have it labelled as "use first address given below", and then
> >    just complain if no addresses are given below.
>
> >    Later when there needs to be something to stop the billing address
> >    from being deleted.
>
> > 2. Related to the previous, there needs to be a constraint so there
> >    must be at least one Address for each customer.
>
> > 3. When editing an existing customer, only that customer's addresses
> >    should be shown in the dropdown for billing address.
>
> > Here's what I've tried...
>
> > I set the billing address field to be optional for now.
>
> > Problem 3 seemed easiest so I decided to tackle that first, and made a
> > bunch of customers and addresses so I could test with the database
> > somewhat populated.
>
> > I found the ForeignKey.limit_choices_to in the documentation but since
> > there's no "self" when I'm setting up the database fields I've no idea
> > how I'd tell it to limit the options to something like
> > self.addresses_set.all(), let alone have that updated as addresses are
> > added, removed, edited in the inline form below.
>
> > I first posted this problem on Stacko Overflow
> > (http://stackoverflow.com/questions/8637912/) and a suggestion was to
> > use a ModelChoiceField. I had a look at the documentation and it
> > wasn't obvious what the difference is between that an ForeignKey, plus
> > it looks like I'd have exactly the same problem as above.
>
> > So I'm totally stuck on that one.
>
> > Next I had a go at the other two problems. It seemed to me (bearing in
> > mind I'm a newbie here) it'd be best to add that logic to the
> > Customer.clean() method -- I could check the number of addresses which
> > had been entered there and raise an Exception if it was zero. At the
> > same time I could set the billing address, if not already set, to the
> > first address given. All sounds simple enough, but apparently not.
>
> > In the Customer.clean() method, I can't seem to get at what was posted
> > as addresses. In there, self.address_set.all().count() is zero. I
> > don't 

Re: Constraints on a one-to-many relationship and related problems

2011-12-28 Thread Dan Gentry
Just looking at the models, I'd like to make a couple of suggestions.

Instead of using a Foreign Key relationship in Customer to indicate
the billing address,  I would include a flag called 'billing_address'
in the Address table that would be set to True for the customer
selected address.

An override of save() in the Address model is then used to enforce the
'only one billing address' rule.

def save(self):
''' This will turn off the billing address flag for all other
addresses for this customer if the new record is selected '''
if self.billing_address:
old_billing_address =
Address.objects.filter(customer=self.customer).filter(billing_flag=
True)
for s in old_billing_address:
s.billing_flag = False
s.save()
super(Address, self).save()

Hope this helps,

Dan

On Dec 28, 6:02 am, Bart Nagel  wrote:
> I'm new to Django. I'm finding it very impressive so far but have hit
> a cluster of problems. I'm using the SVN version.
>
> Sorry for the length of this, I'm just trying to explain as fully as I
> can what I'm trying to do, what I have and what's going wrong.
>
> The relevant parts of my model, in the simplest terms, look like this.
>
>     from django.db import models
>
>     class Address(models.Model):
>         customer = models.ForeignKey("Customer")
>         street = models.CharField(max_length=128)
>         city = models.CharField(max_length=128)
>
>         def __unicode__(self):
>             return "%s, %s" % (self.street, self.city)
>
>     class Customer(models.Model):
>         last_name = models.CharField(blank=True, max_length=64)
>         first_name = models.CharField(blank=True, max_length=64)
>         billing_address = models.ForeignKey("Address", related_name="+")
>
>         def __unicode__(self):
>             return "%s %s" % (self.first_name, self.last_name)
>
> So customers can have many addresses, and one of those addresses is
> pointed to by the customer as being the billing address.
>
> I then have the Customer admin page set up so that Address entries are
> edited inline on the same form.
>
> 1. The billing address should be required, but obviously when it's a
>    new Customer there won't be any addresses on file, so there will be
>    no choices on the billing address dropdown.
>
>    So I need a way to accept a blank selection for billing address,
>    maybe have it labelled as "use first address given below", and then
>    just complain if no addresses are given below.
>
>    Later when there needs to be something to stop the billing address
>    from being deleted.
>
> 2. Related to the previous, there needs to be a constraint so there
>    must be at least one Address for each customer.
>
> 3. When editing an existing customer, only that customer's addresses
>    should be shown in the dropdown for billing address.
>
> Here's what I've tried...
>
> I set the billing address field to be optional for now.
>
> Problem 3 seemed easiest so I decided to tackle that first, and made a
> bunch of customers and addresses so I could test with the database
> somewhat populated.
>
> I found the ForeignKey.limit_choices_to in the documentation but since
> there's no "self" when I'm setting up the database fields I've no idea
> how I'd tell it to limit the options to something like
> self.addresses_set.all(), let alone have that updated as addresses are
> added, removed, edited in the inline form below.
>
> I first posted this problem on Stacko Overflow
> (http://stackoverflow.com/questions/8637912/) and a suggestion was to
> use a ModelChoiceField. I had a look at the documentation and it
> wasn't obvious what the difference is between that an ForeignKey, plus
> it looks like I'd have exactly the same problem as above.
>
> So I'm totally stuck on that one.
>
> Next I had a go at the other two problems. It seemed to me (bearing in
> mind I'm a newbie here) it'd be best to add that logic to the
> Customer.clean() method -- I could check the number of addresses which
> had been entered there and raise an Exception if it was zero. At the
> same time I could set the billing address, if not already set, to the
> first address given. All sounds simple enough, but apparently not.
>
> In the Customer.clean() method, I can't seem to get at what was posted
> as addresses. In there, self.address_set.all().count() is zero. I
> don't really see why -- I can get at the other data which was posted
> to the form as an object, why not the child objects which are being
> posted too?
>
> Perhaps just too early. Following a suggestion in the same Stack
> Overflow thread mentioned above, I figured out how to set up a
> listeners for the pre_save and post_save signals and inspected the
> count of addresses at those points. It's still zero in both cases.
> Even after the save. That was very confusing but from what I've found
> while Googling it's something to do with the database transaction
> having not 

Re: am I understanding sessions correctly?

2011-12-28 Thread Chris Curvey
Thanks for the thoughts, Stuart.

On Dec 23, 2:08 pm, Stuart Laughlin  wrote:
> On Dec 22, 9:01 am, ChrisCurvey wrote:
>
> > The short version:  when processing a request, does Django *always*
> > collect session information from the session store before starting the
> > view?
>
> Yes. However note that django only saves to the session database when
> the session has been modified. It doesn't seem like that's affecting
> you, but I can't be sure.

So long as Django is auto-saving and auto-fetching, I think I should
be OK.  I guess I could set up something to monitor the database
activity.

>
> http://www.djangobook.com/en/2.0/chapter14/
>
> > The long version:
>
> > i have an application that makes heavy use ofAJAX.  When a user
> > changes something on the page, the page fires anAJAXPOST to apply
> > the changes to the database, then a series ofAJAXGETs to refresh
> > other portions of the page.
>
> You say, "then a series ofAJAXGETs" but when is "then"? Presumably
> in the post's callback function? Because otherwise you have no
> guarantee that the POST completes before the GETs fire.

The query is fired from jQuery, and here's my code.  (I realize this
is getting a little far from being Django-specific)

  $.ajax({url: "/hold_time_cost/" ,
  data: {tran_num : $(this).attr('tran_num'),
 value : checked,
 file_number : file_number},
  type: "POST",
  async: false,
  cache: false,
  complete: function(request, status) {
get_unbilled_costs(file_number);
get_held_costs(file_number);
  }
});

>
>
> > Some of the GETs are expensive, so I have some process_response()
> > middleware that caches the HTML generated by the GET in the Django
> > session.  (It's the standard database session store.)  I also have
> > some process_request() middleware that either returns the cached HTML
> > if it can, or invalidates the cache on any POST.
>
> > Just to add to the fun, I have a four identical Django/mod_wsgi
> > instances running behind a round-robin load balancer.  So the POST
> > request might get handled by Django1, the first GET by Django2, the
> > second GET by Django3, and so on.
>
> > My problem is that sometimes the results of the POST are not visible
> > in the results of the GET.  The problem is intermittent, which is
> > leading me to point the finger at my cacheing strategy.  My assumption
> > was that Django would reload the session from the database every time
> > before starting my view code, but I'm wondering if that is not true
> > (or if there is some other issue that I'm not thinking about).
>
> Yes, your caching seems a likely culprit, and so does the asynchronous
> nature of youAJAX(but it seems like you've got a handle on that
> part). I haven't thought through the load balancer bit yet, but
> presumably they are all using the same cache / database / session
> store..?

I'm wondering if maybe I should futz with using the
django.contrib.sessions.backends.cached_db for a session engine.

>
> --Stuart

-- Chris

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Constraints on a one-to-many relationship and related problems

2011-12-28 Thread Bart Nagel
I'm new to Django. I'm finding it very impressive so far but have hit 
a cluster of problems. I'm using the SVN version.

Sorry for the length of this, I'm just trying to explain as fully as I 
can what I'm trying to do, what I have and what's going wrong.

The relevant parts of my model, in the simplest terms, look like this.

from django.db import models

class Address(models.Model):
customer = models.ForeignKey("Customer")
street = models.CharField(max_length=128)
city = models.CharField(max_length=128)

def __unicode__(self):
return "%s, %s" % (self.street, self.city)

class Customer(models.Model):
last_name = models.CharField(blank=True, max_length=64)
first_name = models.CharField(blank=True, max_length=64)
billing_address = models.ForeignKey("Address", related_name="+")

def __unicode__(self):
return "%s %s" % (self.first_name, self.last_name)

So customers can have many addresses, and one of those addresses is 
pointed to by the customer as being the billing address.

I then have the Customer admin page set up so that Address entries are 
edited inline on the same form.

1. The billing address should be required, but obviously when it's a 
   new Customer there won't be any addresses on file, so there will be 
   no choices on the billing address dropdown.

   So I need a way to accept a blank selection for billing address, 
   maybe have it labelled as "use first address given below", and then 
   just complain if no addresses are given below.

   Later when there needs to be something to stop the billing address 
   from being deleted.

2. Related to the previous, there needs to be a constraint so there 
   must be at least one Address for each customer.

3. When editing an existing customer, only that customer's addresses 
   should be shown in the dropdown for billing address.

Here's what I've tried...

I set the billing address field to be optional for now.

Problem 3 seemed easiest so I decided to tackle that first, and made a 
bunch of customers and addresses so I could test with the database 
somewhat populated.

I found the ForeignKey.limit_choices_to in the documentation but since 
there's no "self" when I'm setting up the database fields I've no idea 
how I'd tell it to limit the options to something like 
self.addresses_set.all(), let alone have that updated as addresses are 
added, removed, edited in the inline form below.

I first posted this problem on Stacko Overflow 
(http://stackoverflow.com/questions/8637912/) and a suggestion was to 
use a ModelChoiceField. I had a look at the documentation and it 
wasn't obvious what the difference is between that an ForeignKey, plus 
it looks like I'd have exactly the same problem as above.

So I'm totally stuck on that one.

Next I had a go at the other two problems. It seemed to me (bearing in 
mind I'm a newbie here) it'd be best to add that logic to the 
Customer.clean() method -- I could check the number of addresses which 
had been entered there and raise an Exception if it was zero. At the 
same time I could set the billing address, if not already set, to the 
first address given. All sounds simple enough, but apparently not.

In the Customer.clean() method, I can't seem to get at what was posted 
as addresses. In there, self.address_set.all().count() is zero. I 
don't really see why -- I can get at the other data which was posted 
to the form as an object, why not the child objects which are being 
posted too?

Perhaps just too early. Following a suggestion in the same Stack 
Overflow thread mentioned above, I figured out how to set up a 
listeners for the pre_save and post_save signals and inspected the 
count of addresses at those points. It's still zero in both cases. 
Even after the save. That was very confusing but from what I've found 
while Googling it's something to do with the database transaction 
having not been finished yet. It seems counter-intuitive. Ideally I'd 
like to get at the Address objects before they're committed to the 
database so that I can roll back if necessary (in the case that there 
are no addresses), but after they're committed would do if there was 
no other way -- I could change the Customer object as necessary and 
re-save it or delete it. Not sure how I'd let the user know in that 
case.

But no -- empty address_set.all() at post_save time. I found a monkey 
patch to add a signal for post_transaction 
(https://gist.github.com/247844) and with a small tweak (possibly my 
Python or my Django is too old or new or something) it worked. I set 
up the listener and now I can get at the Address objects from the 
Customer object and edit the Customer if necessary (adding the first 
address as the billing address). But at this point it's too late to 
throw pretty exceptions if something goes wrong, which is a shame.

There's another problem there too. Once the billing address is set to 
one of the addresses 

Re: {% elif %} error

2011-12-28 Thread Mário Neto
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#firstof

2011/12/28 Nikhil Verma 

> Go to this link
>
> https://docs.djangoproject.com/en/dev/ref/templates/builtins/
>
> {% if athlete_list %}
>
> Number of athletes: {{ athlete_list|length }}
> *{% elif athlete_in_locker_room_list %}*
>
> Athletes should be out of the locker room soon!
> {% else %}
> No athletes.
> {% endif %}
>
> press CLTR + F and type elif you will reach there
>
>
>
>
> On Wed, Dec 28, 2011 at 12:38 PM, Tsung-Hsien wrote:
>
>> Thank you all!
>>
>> I don't see the line
>> "New in Django Development version."
>>
>> On Dec 27, 10:44 pm, Tsung-Hsien  wrote:
>> > Hi,
>> > I want to use {% elif %}
>> > my template:
>> > {% if bookmark.hours %}
>> > {{ bookmark.hours }} hours ago
>> > {% elif bookmark.days %}
>> > {{ bookmark.days }} days ago
>> > {% elif bookmark.months %}
>> > {{ bookmark.months }} months ago
>> > {% else %}
>> >  {{ bookmark.years }} years ago
>> > {% endif %}
>> >
>> > show error:
>> > Invalid block tag: 'elif', expected 'else' or 'endif'
>> >
>> > It can work without elif, if use if...else loop.
>> >
>> > my django version is 1.31
>> >
>> > how to solve this?
>> > thanks!!
>>
>> --
>> 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 group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Regards
> Nikhil Verma
> +91-958-273-3156
>
>  --
> 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 group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Att. Mário A. Chaves Neto
Programmer, Designer and U.I. Engineer
MBA - Design Digital

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



raw query placeholder "%(key)s" supported in django?

2011-12-28 Thread ali alizadeh
hi.

in psycopg module, when composing a query, you can use "%(key)s" in your
query instead of "%s", and pass a dictionary instead of a list for actual
parameter.
django docs mention the "%s" syntax for raw queries. i was just wondering
if the other syntax is supported or not, because it can be handy sometimes.

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: project help

2011-12-28 Thread Denis Darii
You can also consider to use pinax: http://pinaxproject.com/

or userena for accounts: http://django-userena.org/

Denis.

On Tue, Dec 27, 2011 at 8:58 PM, Jesramz wrote:

> Hello All,
>
> I would like to create a job search project a lot like monster or
> indeed.
>
> Does anyone have any resources such as other projects or repositories
> similar to what I'm looking for that can push me in the right
> direction? Or any advice whatsoever would also be appreciated.
>
> I am planning on using:
>django registration
>django profiles
>geodjango
>
> Not sure what else yet
>
> --
> 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 group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.