Custom query for ModelChoiceField using request.user.get_profile() as a part of the criteria

2011-06-10 Thread geraldcor
Hello all,

I am wondering how to access a user's profile when creating the
queryset for a ModelChoiceField. I would like to be able to use the
ModelChoiceField to display contacts from another table based on a
parameter saved in the user profile i.e. who =
forms.ModelChoiceField(queryset=Contacts.objects.filter(id__exact=request.user.get_profile().main_company))

Is there a better way to do this (beyond an ajax picker in the
template)?

Greg

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



label_tag in queryset

2011-02-23 Thread geraldcor
Hello all,

When rendering a list of data for a particular model instance, I am
wondering how to access the label_tag attribute for a field when not
using a form.

In my view I get a model instance and pass the object in my context

inspection = inspection.objects.get(pk=3)

Then in my template I want to be able to do the following:

{{ inspection.requester.label_tag }} {{ inspection.requester }}
...

But it seems you can only access label_tag when you are rendering a
form. Any way to do this with a queryset?

Greg

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



MultipleChoiceField Edit form Error

2011-01-24 Thread geraldcor
Hello All,

I am having a problem with my MultipleChoiceField. I have my model
field, form field and choices listed below. When I select choices 1-9,
the edit form shows that these choices have been checked (i.e. save
the form, then view the form for editing again, the previously checked
check boxes are checked and this works using CheckboxSelectMultiple or
the standard Multiple Select Widget). However, when I chose choices 10
or 11 (or beyond), the list gets saved to my table field just fine
([u'1', u'3', u'11']), but when I view the form for editing, choice 11
(UK) is not checked.

It appears that when my Choice is a two digit number (in string
format) it saves just fine, but when the html is being rendered for
the form, the checked attribute is not being checked properly for the
last items.

I also tried changing choice 1 to 12 and that broke it, but then
worked when changed back to 1. Everything saves fine in the table, but
is not rendered correctly and the template tag I wrote to display the
selected choices works just fine with those higher number choices.

MODEL FIELD

targetmarkets = models.CharField(max_length=255, blank=True)

TARGETMARKETS_CHOICES = (
('1', 'Europe'),
('2', 'Asia'),
('3', 'North America'),
('4', 'South America'),
('5', 'Africa'),
('6', 'Canada'),
('7', 'USA'),
('8', 'East Europe'),
('9', 'West Europe'),
('10', 'Australasia'),
('11', 'UK'),
)

FORM FIELD

targetmarkets = forms.MultipleChoiceField(required=False,
widget=forms.CheckboxSelectMultiple, choices=TARGETMARKETS_CHOICES)

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



Admin not using verbose_name on required fields

2010-09-16 Thread geraldcor
Hello all,

I am using the admin and fieldsets to display a change form as usual.
Some fields' labels, even with blank=True are being given the class
required and are not using the verbose_name argument either given via
keyword or positional usage. All fields that really are required
(blank=False) have this same problem. This brings up a few good
questions. Why are certain fields being called required when they are
not required and why are fields with the class required not using the
verbose_name?

http://dpaste.com/hold/244531/

Model snippet and full Admin for the model.

Thanks for any help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Populate Foreign Key after Form is Submitted

2010-06-14 Thread geraldcor
That was perfect. Thank you. I don't look at the admin docs enough I
guess. The following worked:

customers = forms.ModelChoiceField(queryset=Customers.objects.all(),
widget=forms.TextInput)

On Jun 14, 3:03 pm, Lee Hinde  wrote:
> On Mon, Jun 14, 2010 at 1:59 PM, geraldcor  wrote:
> > Hello all,
>
> > I have a model A that has >4000 records in it. I have just created a
> > new model B that has a foreign key to A. I want to be able to create
> > an instance of B and save it which is no problem going the normal
> > routes. However, I like to use Ajax to make the load times faster
> > because a lot of our clients are on slow connections in China. With
> > the foreign key  field being populated by 4000+ values, the
> > load time for the page is quite slow. I would like to leave
> > ModelChoiceField off my form and then populate it in my view (or a
> > hidden input in my form). However, whenever I just try to save the pk
> > number value into the foreign key, I get the error "Cannot assign
> > "u'1783'": "MainNode.customers" must be a "Customers" instance."
>
> > How can I just save a number to the foreign key field? Thanks for any
> > advice and help.
>
> > Greg
>
> If you're talking about this problem in Admin, look at:
>
> http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contri...
>
> If it's your own form, you could do something similar.
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Populate Foreign Key after Form is Submitted

2010-06-14 Thread geraldcor
Hello all,

I have a model A that has >4000 records in it. I have just created a
new model B that has a foreign key to A. I want to be able to create
an instance of B and save it which is no problem going the normal
routes. However, I like to use Ajax to make the load times faster
because a lot of our clients are on slow connections in China. With
the foreign key  field being populated by 4000+ values, the
load time for the page is quite slow. I would like to leave
ModelChoiceField off my form and then populate it in my view (or a
hidden input in my form). However, whenever I just try to save the pk
number value into the foreign key, I get the error "Cannot assign
"u'1783'": "MainNode.customers" must be a "Customers" instance."

How can I just save a number to the foreign key field? Thanks for any
advice and help.

Greg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: manager.raw returning Capitalized field names

2010-05-19 Thread geraldcor
Russ,

>As for templates - they don't ever use the CamelCase name. They
>exclusively use the model names, and there's no 'raw query' equivalent
>for templates.

This is the problem that is presenting the possible bug. I have to use
{{ m.SomeField }} in my template rather than {{ m.somefield }} as you
suggest should always be the case.

I am using a raw query because I couldn't for the life of me get the
related object query for Checkin.objects.filter(...) to work.
Sometimes I actually find the ORM more confusing than raw sql ;)

Greg

On May 15, 5:19 am, Russell Keith-Magee 
wrote:
> On Fri, May 14, 2010 at 5:29 AM, geraldcor  wrote:
> > Hello,
>
> > Some background first. I am working with a legacy database that is not
> > only legacy, it is legacy Microsoft access so there is some hacking
> > going on. I am accessing a MySQL backend and my models are set up to
> > use the existing tables/field names. When I use regular old ORM
> > queries, Everything works as normal and I can access fields using a
> > for loop and iterator.fieldname.
>
> > In order to access the joined fields between two tables, I had to
> > resort to themanager.rawsyntax. Here is my syntax
>
> > confirm_data = Checkin.objects.raw('SELECT * FROM Checkin JOIN
> > CheckinTests ON Checkin.SampleID = CheckinTests.SampleID WHERE
> > Checkin.DateArrived = %s AND Checkin.Company = %s', [date_arrived,
> > company_name])
>
> > 1. I have to use the legacy db table names and field names i.e.
> > CamelCase names
> > 2. Once the query is executed and either in the shell or a template,
> > when I iterate over the queryset for the main table I can use
> > c.fieldname but for the joined table I have to use c.FieldName. It's
> > as if the joined table isn't returning the model names but the table
> > names from MySQL. Is this a bug? It's kindof annoying to have to use
> > two different syntaxes in my templates.
>
> It's hard to tell if this is a bug, but my initial reaction is
> probably not -- although that is moderated by the fact that I'm a
> little hazy on what you are describing. This is mostly because I'm
> getting confused over which bits are MySQL, which bits are Access,
> which bits are template code, and why joining matters at all.
>
> There are two completely independent naming domains in use here
>  1) The attributes on a Django model
>  2) The field names on the SQL database.
>
> By way of example, if you have the following model:
>
> class MyModel(Model):
>     fieldname = CharField(max_length=100, db_colum='FieldName')
>
> This defines a Django model with a field called 'fieldname', backed by
> a database column named 'FieldName'. You can create instances and
> assign values using the lowercased name:
>
> >>> m = MyModel()
> >>> m.fieldname = 'ham'
> >>> m.save()
>
> and the underlying SQL that is executed will use the db_column:
>
> SELECT FieldName ... FROM myapp_mymodel WHERE ...
>
> If you're issuing raw queries, then yes - you will need to deal with
> the CamelCase names, but that's because you're manually issuing SQL.
> However, if your queries are as simple as the example you provide, you
> shouldn't even need to use raw queries - you should be able to do a
> simple MyModel.objects.filter(...) call, and not worry about the
> column names at all.
>
> As for templates - they don't ever use the CamelCase name. They
> exclusively use the model names, and there's no 'raw query' equivalent
> for templates.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://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-us...@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.



manager.raw returning Capitalized field names

2010-05-13 Thread geraldcor
Hello,

Some background first. I am working with a legacy database that is not
only legacy, it is legacy Microsoft access so there is some hacking
going on. I am accessing a MySQL backend and my models are set up to
use the existing tables/field names. When I use regular old ORM
queries, Everything works as normal and I can access fields using a
for loop and iterator.fieldname.

In order to access the joined fields between two tables, I had to
resort to the manager.raw syntax. Here is my syntax

confirm_data = Checkin.objects.raw('SELECT * FROM Checkin JOIN
CheckinTests ON Checkin.SampleID = CheckinTests.SampleID WHERE
Checkin.DateArrived = %s AND Checkin.Company = %s', [date_arrived,
company_name])

1. I have to use the legacy db table names and field names i.e.
CamelCase names
2. Once the query is executed and either in the shell or a template,
when I iterate over the queryset for the main table I can use
c.fieldname but for the joined table I have to use c.FieldName. It's
as if the joined table isn't returning the model names but the table
names from MySQL. Is this a bug? It's kindof annoying to have to use
two different syntaxes in my templates.

Hope this makes sense, please let me know if I need to clarify.

Greg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: AdminField Rendering Question

2010-05-05 Thread geraldcor
Oh of course. Probably the one file I didn't look at. I think a
subclass is in order. Thank you very much for the direction.

Greg

On May 5, 5:01 am, patrickk  wrote:
> there you 
> go:http://code.djangoproject.com/browser/django/trunk/django/contrib/adm...
>
> unfortunately, it´s all hardcoded. if you need to customize the
> widget, you may want to write your own and subclass the given one.
>
> hope that answers your question.
>
> regards,
> patrick
>
> On 5 Mai, 01:43, geraldcor  wrote:
>
>
>
> > Hello all,
>
> > I have been pouring over the django source trying to figure out where
> > the "Currently: "/images/..."" gets added to ImageField upload fields
> > after an image has been uploaded in the admin interface. I wonder this
> > because I would like to do some custom manipulation with the image
> > field and as I was searching for how to do this I just couldn't find
> > anything about how any form fields are rendered for that matter. I
> > understand how they are constructed and how the template is rendered
> > but I can't for the life of me figure out how the actual field is
> > rendered and represented in the html form. Could anyone please offer
> > me some insight into this. I really love the "Currently:" that shows
> > up and I would like to see how it's done.
>
> > Thank you for helping out a very confused person.
>
> > Greg.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://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-us...@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.



AdminField Rendering Question

2010-05-04 Thread geraldcor
Hello all,

I have been pouring over the django source trying to figure out where
the "Currently: "/images/..."" gets added to ImageField upload fields
after an image has been uploaded in the admin interface. I wonder this
because I would like to do some custom manipulation with the image
field and as I was searching for how to do this I just couldn't find
anything about how any form fields are rendered for that matter. I
understand how they are constructed and how the template is rendered
but I can't for the life of me figure out how the actual field is
rendered and represented in the html form. Could anyone please offer
me some insight into this. I really love the "Currently:" that shows
up and I would like to see how it's done.

Thank you for helping out a very confused person.

Greg.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ChoiceField invalid literal for int() with base 10: ''

2010-04-13 Thread geraldcor
That was a very good guess. I tried it but it didn't work.

On Apr 13, 12:46 pm, johan sommerfeld 
wrote:
>  You could try using initial=0.
>
> /J
>
> On Tuesday, April 13, 2010, geraldcor  wrote:
> > Hello all,
>
> > I know the error "invalid literal for int() with base 10: '' " has
> > been discussed a lot in the past, but this seems to be unique to my
> > situation.
>
> > I have 2 choice fields as defined below for both the model and form:
>
> > models.py
> > class Checkin(models.Model):
> > ...
> > content = models.IntegerField(db_column='Content', blank=True,
> > default=0)
> > specie = models.IntegerField(db_column='Specie', blank=True,
> > default=0)
> > (I have tried a few variations on default and null=True etc)
> > (This is accessing a legacy database)
>
> > forms.py
> > CONTENT_CHOICES=(
> >         (2, 'IDFB USA Method'),
> >         (5, 'IDFB ADFC Official'),
> >         (7, 'IDFB Canada Method'),
> >         (8, 'IDFB Australian Method'),
> >         (9, 'General Report Format'),
> >         (3, 'European Method'),
> >         (4, 'Japanese Method'),
> >         (6, 'California Method'),
> >         (10, 'GB/T (Chinese)'),
> > )
> > SPECIES_CHOICES=(
> >         (4, 'Down'),
> >         (5, 'Feather'),
> >         (6, 'Down and Feather'),
> >         (7, 'Pre-Down'),
> >         (8, 'Pre-Feather'),
> >         (9, 'Pre-Down and Feather'),
> > )
> > class CheckinForm(ModelForm):
> > ...
> > content = forms.ChoiceField(required=False, choices=CONTENT_CHOICES,
> > widget=forms.RadioSelect())
> > specie = forms.ChoiceField(required=False, choices=SPECIES_CHOICES,
> > widget=forms.RadioSelect())
>
> > When I try to save the form and I do not select anything for these two
> > fields I get the above error and the two fields are not listed in the
> > POST area of the Request Information section of the error page.
> > However, if I select something for each of those tests, the form saves
> > just fine and all is well. I am using MySQL and the fields are INT(10)
> > Default Value 0 or Null (I've tried both) and Not Null has been
> > selected and not selected just for testing.
>
> > I assume the problem has something to do with trying to save an empty
> > string in an INT field, but my checkboxes that are unselected do not
> > raise errors and the only thing different is that they are TINYINT(1).
> > Any ideas on why this is happening. I'm trying to give as much info
> > without being too verbose. I will post more if needs be.
>
> > Thanks for all help both past and future.
>
> > Greg
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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-us...@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.



ChoiceField invalid literal for int() with base 10: ''

2010-04-13 Thread geraldcor
Hello all,

I know the error "invalid literal for int() with base 10: '' " has
been discussed a lot in the past, but this seems to be unique to my
situation.

I have 2 choice fields as defined below for both the model and form:

models.py
class Checkin(models.Model):
...
content = models.IntegerField(db_column='Content', blank=True,
default=0)
specie = models.IntegerField(db_column='Specie', blank=True,
default=0)
(I have tried a few variations on default and null=True etc)
(This is accessing a legacy database)

forms.py
CONTENT_CHOICES=(
(2, 'IDFB USA Method'),
(5, 'IDFB ADFC Official'),
(7, 'IDFB Canada Method'),
(8, 'IDFB Australian Method'),
(9, 'General Report Format'),
(3, 'European Method'),
(4, 'Japanese Method'),
(6, 'California Method'),
(10, 'GB/T (Chinese)'),
)
SPECIES_CHOICES=(
(4, 'Down'),
(5, 'Feather'),
(6, 'Down and Feather'),
(7, 'Pre-Down'),
(8, 'Pre-Feather'),
(9, 'Pre-Down and Feather'),
)
class CheckinForm(ModelForm):
...
content = forms.ChoiceField(required=False, choices=CONTENT_CHOICES,
widget=forms.RadioSelect())
specie = forms.ChoiceField(required=False, choices=SPECIES_CHOICES,
widget=forms.RadioSelect())

When I try to save the form and I do not select anything for these two
fields I get the above error and the two fields are not listed in the
POST area of the Request Information section of the error page.
However, if I select something for each of those tests, the form saves
just fine and all is well. I am using MySQL and the fields are INT(10)
Default Value 0 or Null (I've tried both) and Not Null has been
selected and not selected just for testing.

I assume the problem has something to do with trying to save an empty
string in an INT field, but my checkboxes that are unselected do not
raise errors and the only thing different is that they are TINYINT(1).
Any ideas on why this is happening. I'm trying to give as much info
without being too verbose. I will post more if needs be.

Thanks for all help both past and future.

Greg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Use a queryset as values for model insert

2010-03-03 Thread geraldcor
Hello all,

I have a form for submitting samples. After the user submits a sample,
I would like to give them a button that says "Use last form to fill in
this form" or whatever. Basically, the way I have thought to do this
is:

last_sample = SSF.objects.filter(ssfvalue=request.user.id).order_by('-
id')[:1].values() which would give me a tuple containing a dictionary
of key:value pairs of the last submitted data.

Now I would like to be able to just plop that into a new row in my
table and then present that to the user to verify/alter etc. I am
using a form wizard which is why intitial values won't work (I think).

I have tried all sort of string concatenation, tuples, lists - can't
figure out how to do

s=SSF(name="the name", test1=1...)
s.save()

Thanks for any advice.

Greg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Use django auth system with ruby on rails

2010-02-19 Thread geraldcor
CAS sounds very interesting as a SSO. I may give that a try, as well
as maybe just perform some unit tests just to make sure I know what is
going on under the hood. Thank you all for your much needed input.

Greg

On Feb 19, 10:32 am, Phlip  wrote:
> geraldcor wrote:
> > and all will be good - I think. Does that sound reasonable?
>
> Been there done that. But...
>
> >     using the given algorithm ('md5', 'sha1' or 'crypt').
>
>                                                          ^
> Pick the right one wisely!
>
> I would start with unit tests that attack known passwords, entered
> into the View, and compare them with their hashed results extracted
> from the DB.
>
> --
>   Phlip
>  http://penbird.tumblr.com/post/398311631/avatar-redux

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Use django auth system with ruby on rails

2010-02-18 Thread geraldcor
All of your comments prompted me to start reverse engineering what
django does and I came across the check_password method which just
separates the algorithm, salt and hash and then sends it to the
following method to compare the raw password to the hash password. So
basically, in Ruby, I can do the same thing using a similar library
and all will be good - I think. Does that sound reasonable?

Greg

def get_hexdigest(algorithm, salt, raw_password):
"""
Returns a string of the hexdigest of the given plaintext password
and salt
using the given algorithm ('md5', 'sha1' or 'crypt').
"""
raw_password, salt = smart_str(raw_password), smart_str(salt)
if algorithm == 'crypt':
try:
import crypt
except ImportError:
raise ValueError('"crypt" password algorithm not supported
in this environment')
return crypt.crypt(raw_password, salt)

if algorithm == 'md5':
return md5_constructor(salt + raw_password).hexdigest()
elif algorithm == 'sha1':
return sha_constructor(salt + raw_password).hexdigest()
raise ValueError("Got unknown password algorithm type in
password.")

On Feb 18, 8:35 am, Alex Robbins 
wrote:
> You could have a secure url that the RoR apps redirect to if the user
> isn't authenticated with Rails. That url would have the login_required
> decorator. If they successfully login on the django side (or are
> already logged in), then they get redirected with some sort of get
> variable user id + hash combo. You could check the validity of the
> user id from the hash (using a shared secret).
>
> Alex
>
> On Feb 17, 4:09 pm, geraldcor  wrote:
>
> > Hello all,
>
> > Internally, we have some RoR apps and Django apps. Our main website
> > runs on Django and is considered to be the main portal for all other
> > apps. Currently, we have a Rails authentication system and a Django
> > authentication system. We want to have one user table to authorize
> > against.
>
> > The only problem I see is that the password stored in auth_user is
> > salted and hashed and impossible to get at because the salt is not
> > saved. How can I use the django auth_user inRubyOn Rails?
>
> > I have found this:http://docs.djangoproject.com/en/dev/howto/apache-auth/
> > but I don't know if that will work on therubyserver. Both ror and
> > django applications that we want to authenticate are on the same
> > server and use the same db (except our main website which is on
> > webfaction - but that's a different story I will tackle later -
> > possibly replication?).
>
> > So, anyone know how to a) access the raw string from auth_user or b)
> > set upruby(or other language and extrapolate) to properly interpret
> > the password hash?
>
> > Thanks for listening.
>
> > Greg
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Use django auth system with ruby on rails

2010-02-17 Thread geraldcor
Hello all,

Internally, we have some RoR apps and Django apps. Our main website
runs on Django and is considered to be the main portal for all other
apps. Currently, we have a Rails authentication system and a Django
authentication system. We want to have one user table to authorize
against.

The only problem I see is that the password stored in auth_user is
salted and hashed and impossible to get at because the salt is not
saved. How can I use the django auth_user in Ruby On Rails?

I have found this: http://docs.djangoproject.com/en/dev/howto/apache-auth/
but I don't know if that will work on the ruby server. Both ror and
django applications that we want to authenticate are on the same
server and use the same db (except our main website which is on
webfaction - but that's a different story I will tackle later -
possibly replication?).

So, anyone know how to a) access the raw string from auth_user or b)
set up ruby (or other language and extrapolate) to properly interpret
the password hash?

Thanks for listening.

Greg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-mptt TreeNodeChoiceField

2010-02-11 Thread geraldcor
Sorry to ask such a seemingly silly question, but how do I use
TreeNodeChoiceField in a ModelForm. To create a new node, I created a
ModelForm, and, like other ModelForms, I thought I could just override
the normal form widget. Here are my classes

class Folder(models.Model):
parent = models.ForeignKey('self', null=True, blank=True,
related_name='children')
name = models.CharField(max_length=20, unique=True)

class FolderForm(ModelForm):
parent = TreeNodeChoiceField(queryset=Folder.tree.all(),
level_indicator=u'+--')

class Meta:
model=Folder

I get the error AttributeError: type object 'Folder' has no attribute
'tree'

If I move that statement to the Model class, I don't get the error,
but I can't use that 'tree' Manager.

if I change Folder.tree.all() to
Folder.objects.all().order_by('tree_id') it works mostly well, but
doesn't display the tree nicely like tree.all is supposed to. The docs
are a little ambiguous on the usage of this form field.

Any thoughts on a) how I can use tree manager appropriately or b) hack
it so that I get a queryset that mimics tree.all()?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Cannot Click Into Internet Explorer Input Text Field

2010-01-06 Thread geraldcor
For those interested: It was a z-index issue. I set my main content
div to z-index: -1; so that my drop down menus would not get hidden in
IE. This however masked my input fields. So, I ended up removing that
z-index and giving my #nav a z-index of 1000. Did the trick.

Greg

On Jan 5, 6:14 pm, geraldcor  wrote:
> Hello All,
>
> I have recently run into a very weird internet explorer problem. I
> cannot enter any of my text input boxes unless I carefully hover my
> mouse near the top or bottom edge of the field. The cursor does not
> change until I get to the very top of the field. It works fine in all
> other browsers but IE6, 7 and 8 have all shown this problem. I can
> click into the google CSE field on my page and other fields on other
> sites, but the field that django is producing give me this problem.
> Any ideas on how to fix it? It is kind of critical that this gets
> fixed.
>
> Thanks for all of you help.
>
> Greg
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Cannot Click Into Internet Explorer Input Text Field

2010-01-05 Thread geraldcor
Hello All,

I have recently run into a very weird internet explorer problem. I
cannot enter any of my text input boxes unless I carefully hover my
mouse near the top or bottom edge of the field. The cursor does not
change until I get to the very top of the field. It works fine in all
other browsers but IE6, 7 and 8 have all shown this problem. I can
click into the google CSE field on my page and other fields on other
sites, but the field that django is producing give me this problem.
Any ideas on how to fix it? It is kind of critical that this gets
fixed.

Thanks for all of you help.

Greg
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Initial values for formwizard form

2009-12-02 Thread geraldcor
Ok, so I'm a little embarrassed as usual. basically I was checking for
a step without defining it. I assumed I could just use the step that
is passed but that didn't seem to work for the if statement. So I just
eliminated the if statement and all is well. Not perfect, but I can at
least move on.

On Dec 2, 3:53 pm, geraldcor  wrote:
> So I successfully used this method to add initial values using
> parse_params as I was dealing with step 0. However, now the client
> wants the form order changed so that what was step 0 is now step 2. I
> tried using process_step in the exact same way as parse_params, but
> the values are not filled in. I can't figure out how to use
> process_step like I was able to use parse_params.
>
> this is what I tried
>
> def process_step(self, request, form, step):
>                 profile={}
>                 profile=request.user.get_profile()
>                 if step == 2:
>                         init={
>                                 'company': profile.defaultcompany,
>                                 'contact': profile.defaultcontact,
>                                 'address1': profile.defaultaddress1,
>                                 'address2': profile.defaultaddress2,
>                                 'address3': profile.defaultaddress3,
>                                 'city': profile.defaultcity,
>                                 'state': profile.defaultstate,
>                                 'zip': profile.defaultzip,
>                                 'country': profile.defaultcountry,
>                                 'faxareacode': profile.defaultfaxareacode,
>                                 'fax': profile.defaultfax,
>                                 'areacode': profile.defaultareacode,
>                                 'phone': profile.defaultphone,
>                                 'email': profile.defaultemail,
>                                 'billingcompany': profile.billingcompany,
>                                 'billingname': profile.billingname,
>                                 'billingaddress1': profile.billingaddress1,
>                                 'billingaddress2': profile.billingaddress2,
>                                 'billingaddress3': profile.billingaddress3,
>                                 'billingcity': profile.billingcity,
>                                 'billingstate': profile.billingstate,
>                                 'billingzip': profile.billingzip,
>                                 'billingcountry': profile.billingcountry,
>                                 'billingfaxareacode': 
> profile.billingfaxareacode,
>                                 'billingfax': profile.billingfax,
>                                 'billingareacode': profile.billingareacode,
>                                 'billingphone': profile.billingphone,
>                                 'billingemail': profile.billingemail,
>                         }
>                         if profile.sendreportsto:
>                                 init['sendreportsto']=profile.sendreportsto
>                         else:
>                                 init['sendreportsto']='Please use the 
> format:\nName n...@email.com,
> \nName2 na...@email.com'
>                         self.initial[2]=init
> Thanks for any more help.
>
> On Nov 19, 5:56 pm, geraldcor  wrote:
>
> > This worked perfectly. Thank you. I used parse_params because I needed
> > to add default company profile stuff to the first wizard form. Thank
> > you again for clearing up my ignorance.
>
> > Greg
>
> > On Nov 18, 9:10 pm, "Mark L."  wrote:
>
> > > On Nov 19, 1:28 am, geraldcor  wrote:
>
> > > > Ok,
>
> > > > Here is how I do it if I am using a regularformwith a regular view:
>
> > > > profile = request.user.get_profile()
> > > >form= MyForm('company': profile.defaultcompany, 'contact':
> > > > profile.defaultcontact, etc...})
> > > > return render_to_response('forms/submit.html', {'form':form},
> > > > context_instance=RequestContext(request))
>
> > > > pretty simple and basic.
>
> > > > How do I do this with aformwizard?
>
> > > > Greg
>
> > > > On Nov 17, 3:39 pm, geraldcor  wrote:
>
> > > > > Hello all,
>
> > > > &

Re: Initial values for formwizard form

2009-12-02 Thread geraldcor
So I successfully used this method to add initial values using
parse_params as I was dealing with step 0. However, now the client
wants the form order changed so that what was step 0 is now step 2. I
tried using process_step in the exact same way as parse_params, but
the values are not filled in. I can't figure out how to use
process_step like I was able to use parse_params.

this is what I tried

def process_step(self, request, form, step):
profile={}
profile=request.user.get_profile()
if step == 2:
init={
'company': profile.defaultcompany,
'contact': profile.defaultcontact,
'address1': profile.defaultaddress1,
'address2': profile.defaultaddress2,
'address3': profile.defaultaddress3,
'city': profile.defaultcity,
'state': profile.defaultstate,
'zip': profile.defaultzip,
'country': profile.defaultcountry,
'faxareacode': profile.defaultfaxareacode,
'fax': profile.defaultfax,
'areacode': profile.defaultareacode,
'phone': profile.defaultphone,
'email': profile.defaultemail,
'billingcompany': profile.billingcompany,
'billingname': profile.billingname,
'billingaddress1': profile.billingaddress1,
'billingaddress2': profile.billingaddress2,
'billingaddress3': profile.billingaddress3,
'billingcity': profile.billingcity,
'billingstate': profile.billingstate,
'billingzip': profile.billingzip,
'billingcountry': profile.billingcountry,
'billingfaxareacode': 
profile.billingfaxareacode,
'billingfax': profile.billingfax,
'billingareacode': profile.billingareacode,
'billingphone': profile.billingphone,
'billingemail': profile.billingemail,
}
if profile.sendreportsto:
init['sendreportsto']=profile.sendreportsto
else:
init['sendreportsto']='Please use the 
format:\nName n...@email.com,
\nName2 na...@email.com'
self.initial[2]=init
Thanks for any more help.

On Nov 19, 5:56 pm, geraldcor  wrote:
> This worked perfectly. Thank you. I used parse_params because I needed
> to add default company profile stuff to the first wizard form. Thank
> you again for clearing up my ignorance.
>
> Greg
>
> On Nov 18, 9:10 pm, "Mark L."  wrote:
>
> > On Nov 19, 1:28 am, geraldcor  wrote:
>
> > > Ok,
>
> > > Here is how I do it if I am using a regularformwith a regular view:
>
> > > profile = request.user.get_profile()
> > >form= MyForm('company': profile.defaultcompany, 'contact':
> > > profile.defaultcontact, etc...})
> > > return render_to_response('forms/submit.html', {'form':form},
> > > context_instance=RequestContext(request))
>
> > > pretty simple and basic.
>
> > > How do I do this with aformwizard?
>
> > > Greg
>
> > > On Nov 17, 3:39 pm, geraldcor  wrote:
>
> > > > Hello all,
>
> > > > I began making aformthat used request.user.get_profile to get
> > > > default values for company name, phone, email etc. I have since
> > > > decided to move to a formwizard to split things up. I have no idea how
> > > > to override methods for the formwizard class to be able to include
> > > > thoseinitialvalues in theform. Can someone please help me with this
> > > > problem or point me to the proper help? I have come up short with all
> > > > of my searching. Thanks.
>
> > Hello,
>
> > The *initial* values for the forms in aformwizardare stored in the
> > self.initial[] list. It means, that to set setini

Pass URL variable to formwizard like a normal form in views.py

2009-12-01 Thread geraldcor
No normally I can use something lie /foo/edit/35/ and I can edit the
record whose pk is 35. Now with this, I have a url pattern like
(r'^edit/(?P\d+)/$', 'edit'), which points to def edit
(request, ssf_id): in my views.py.

For my formwizard, by overriding various methods I have successfully
made it so that I can edit an instance by using a view to capture the
above url pattern and instead of passing it to 'edit' I pass it to
'edit_wizard' which looks like this:
@login_required
def edit_wizard(request, ssf_id):
instance = get_object_or_404(SSF, pk=ssf_id)
return EDIT_SSFWizard([SSF1, SSF2, SSF3])(request, instance=instance)

This works perfectly. However, there has been a request to have a
listing of the items that the user has already selected so they can
easily see what they have or maybe left off.

Normally I would use something like s=SSF.objects.filter(id=ssf_id)
using the variable from the url and then pass that as a context to the
template so I have my form instance as well as a context full of data.

So I keep putting ssf_id in various methods in my formwizard class to
only have error after error. Any ideas on how to pass this other
variable so I can use the variable to perform a query as below (line
3):

def render_template(self, request, form, previous_fields, step,
max_step, context=None):
context = context or {}
context=SSF.objects.filter(pk=ssf_id).values
()--Look at this Line please
return render_to_response(self.get_template(step), dict
(context=context,
next_step_field=self.next_step_field_name,
max_step_field=self.max_step_field_name,
max_step=max_step,
step_field=self.step_field_name,
step0=step,
step=step + 1,
step_count=self.num_steps(),
form=form,
previous_fields=previous_fields
), context_instance=RequestContext(request))

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Initial values for formwizard form

2009-11-19 Thread geraldcor
This worked perfectly. Thank you. I used parse_params because I needed
to add default company profile stuff to the first wizard form. Thank
you again for clearing up my ignorance.

Greg

On Nov 18, 9:10 pm, "Mark L."  wrote:
> On Nov 19, 1:28 am, geraldcor  wrote:
>
>
>
> > Ok,
>
> > Here is how I do it if I am using a regularformwith a regular view:
>
> > profile = request.user.get_profile()
> >form= MyForm('company': profile.defaultcompany, 'contact':
> > profile.defaultcontact, etc...})
> > return render_to_response('forms/submit.html', {'form':form},
> > context_instance=RequestContext(request))
>
> > pretty simple and basic.
>
> > How do I do this with aformwizard?
>
> > Greg
>
> > On Nov 17, 3:39 pm, geraldcor  wrote:
>
> > > Hello all,
>
> > > I began making aformthat used request.user.get_profile to get
> > > default values for company name, phone, email etc. I have since
> > > decided to move to a formwizard to split things up. I have no idea how
> > > to override methods for the formwizard class to be able to include
> > > thoseinitialvalues in theform. Can someone please help me with this
> > > problem or point me to the proper help? I have come up short with all
> > > of my searching. Thanks.
>
> Hello,
>
> The *initial* values for the forms in aformwizardare stored in the
> self.initial[] list. It means, that to set setinitialvalues for theformin 
> step X you do the following:
>
> init = {
>     'key1':'val1',
>     'key2':'val2',
>     etc..
>
> }
>
> self.initial[X] = init
>
> The best (and, indeed, about the only place to handle this) is the
> process_step method of thewizardinstance (or parse_params, if you
> need to setinitialvalues for theformin step 0).
>
> Hope that helps
>
> Mark

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Initial values for formwizard form

2009-11-18 Thread geraldcor
Ok,

Here is how I do it if I am using a regular form with a regular view:

profile = request.user.get_profile()
form = MyForm('company': profile.defaultcompany, 'contact':
profile.defaultcontact, etc...})
return render_to_response('forms/submit.html', {'form': form},
context_instance=RequestContext(request))

pretty simple and basic.

How do I do this with a form wizard?

Greg

On Nov 17, 3:39 pm, geraldcor  wrote:
> Hello all,
>
> I began making a form that used request.user.get_profile to get
> default values for company name, phone, email etc. I have since
> decided to move to a formwizard to split things up. I have no idea how
> to override methods for the formwizard class to be able to include
> those initial values in the form. Can someone please help me with this
> problem or point me to the proper help? I have come up short with all
> of my searching. 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-us...@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=.




Initial values for formwizard form

2009-11-17 Thread geraldcor
Hello all,

I began making a form that used request.user.get_profile to get
default values for company name, phone, email etc. I have since
decided to move to a formwizard to split things up. I have no idea how
to override methods for the formwizard class to be able to include
those initial values in the form. Can someone please help me with this
problem or point me to the proper help? I have come up short with all
of my searching. 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-us...@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=.




Re: Javascript working on development, not apache

2009-09-11 Thread geraldcor

Hehe...well, tiredness has proven yet again to be a viscous enemy. I
forgot that I changed jquery-1.3.2.min.js to jquery.min.js. the
console cleared that right up. Sorry for the stupid mistake. Thanks
Tiago.

Greg

On Sep 11, 9:51 am, Tiago Serafim  wrote:
> Open the Firefox console and try to see what's going on.
>
>
>
> On Fri, Sep 11, 2009 at 12:44 PM, geraldcor  wrote:
>
> > Hello all,
>
> > I have a site that has quite a bit of javascript/jquery going on. All
> > of this works fine on my development server, but basically no
> > javascript works when I deploy on Apache. This previously worked on
> > this same site before some changes (suspiscious, I know) and other
> > sites work fine on the same webserver.
>
> > I suspect it is bad code that is making the whole thing come to a
> > screeching halt, but why would it work in the development server and
> > not Apache?
>
> > Most of my js is linked. Oh, maybe I should make it local and see what
> > that does. I will try that and if it works, I will respond to my own
> > problem, if not, I will leave this open.
>
> > Thanks for any help.
>
> > Greg
>
> --
> Tiago Serafim
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Javascript working on development, not apache

2009-09-11 Thread geraldcor

Hello all,

I have a site that has quite a bit of javascript/jquery going on. All
of this works fine on my development server, but basically no
javascript works when I deploy on Apache. This previously worked on
this same site before some changes (suspiscious, I know) and other
sites work fine on the same webserver.

I suspect it is bad code that is making the whole thing come to a
screeching halt, but why would it work in the development server and
not Apache?

Most of my js is linked. Oh, maybe I should make it local and see what
that does. I will try that and if it works, I will respond to my own
problem, if not, I will leave this open.

Thanks for any help.

Greg
--~--~-~--~~~---~--~~
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: edit form not working with imagefield

2009-07-08 Thread geraldcor

Thank you all. This plugin really did the trick http://malsup.com/jquery/form/.
One line of code makes it work and you can expand from there. Worked
really well. I highly recommend it for form uploads with ajax and
jquery.

On Jul 7, 3:02 pm, Xiong Chiamiov  wrote:
> On Jul 7, 1:22 pm, Adam Jenkins  wrote:
>
> > I know that Dojo allows one to upload files with Ajax. It uses an iframe as
> > a work around.
>
> From what I remember from when I was doing something like this a good
> year ago, using an iframe is the accepted way of uploading files with
> ajax.  You'll find tutorials, articles and blogposts all over the net
> about doing so with your favorite javascript library.
>
> In particular, take a look 
> here:http://stackoverflow.com/questions/166221/how-can-i-upload-files-asyn...
--~--~-~--~~~---~--~~
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: edit form not working with imagefield

2009-07-07 Thread geraldcor

Oh. That's a problem. Ok. Thanks. Am I going to have to scrap the ajax
idea if I want to edit the image? Any other workarounds?

Thanks for the reply.

On Jul 7, 11:20 am, Alex Gaynor  wrote:
> On Tue, Jul 7, 2009 at 12:16 PM, geraldcor  wrote:
>
> > I have a form that is being added via jquery ajax. I can add a new
> > record, including images just fine. Works like a dream. However, when
> > I go to edit the form, every field will update except for the image
> > field. I choose a new image from the browse button, the filepath loads
> > up and when I submit the form, the image field does not change - the
> > table field filepath does not change. Any ideas on this one?
>
> > As as aside, in case anyone wants to tackle this one, I can't use the
> > success: portion of the jQuery.ajax() function. It just skips that
> > step. Could this be related to the imagefield not updating?
>
> > My view:
> > def edit_blog(request, blg_id):
> >        a = Companyblog.objects.get(pk=blg_id)
> >        if request.method == 'POST':
> >                form=CompanyblogForm(request.POST, request.FILES,
> > instance=a)
> >                if form.is_valid():
> >                        form_data=form.save()
> >                        return HttpResponse("Success")
> >        else:
> >                form = CompanyblogForm(instance=a)
> >                return render_to_response('blogedit.html', {'form': form,
> > 'blg_id':
> > blg_id})
>
> > I will add more code as needed. Thanks for any and all help.
>
> Ajax requests don't send file data.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



edit form not working with imagefield

2009-07-07 Thread geraldcor

I have a form that is being added via jquery ajax. I can add a new
record, including images just fine. Works like a dream. However, when
I go to edit the form, every field will update except for the image
field. I choose a new image from the browse button, the filepath loads
up and when I submit the form, the image field does not change - the
table field filepath does not change. Any ideas on this one?

As as aside, in case anyone wants to tackle this one, I can't use the
success: portion of the jQuery.ajax() function. It just skips that
step. Could this be related to the imagefield not updating?

My view:
def edit_blog(request, blg_id):
a = Companyblog.objects.get(pk=blg_id)
if request.method == 'POST':
form=CompanyblogForm(request.POST, request.FILES, instance=a)
if form.is_valid():
form_data=form.save()
return HttpResponse("Success")
else:
form = CompanyblogForm(instance=a)
return render_to_response('blogedit.html', {'form': form, 
'blg_id':
blg_id})

I will add more code as needed. Thanks for any and all help.
--~--~-~--~~~---~--~~
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: Empty [] using objects.all() on legacy database

2009-06-19 Thread geraldcor

Ok, so I feel a bit silly, but it was because I had a column name in
my db called Discount% and I am assuming the % is screwing it up.

Now the question becomes how do I escape the % or do I have to rename
my db column (please god not the latter as that would entail a whole
mess of rewriting stuff). I already tried some unicode stuff but I'm
fairly untrained in that area. Any ideas?

Thanks

Greg

On Jun 18, 4:41 pm, geraldcor  wrote:
> Hello all,
>
> I am trying to work with a legacy database and I ran inspectdb and
> have a model with the 2 tables that I want to use. The first table,
> the main table is not working at all. The second table which is
> related via a foreign key seems to be working just fine. Here are the
> symptoms:
>
> In the shell I import my tables, to c=Customers.objects.all()
> c
> [] which is an empty dictionary or tuple (sorry for the confusion)
>
> however if I do t=Tblcontacts.objects.all()
> t
> [big long list of Tblcontacts objects] and I can even utilize this
> data in a template via a view.
>
> I can't figure out why one would work while the other does not.
>
> here are the first view field definitions in my model in case that
> offers any insight.
>
> #The customers table that doesn't work.
> class Customers(models.Model):
>     idflcustomernum = models.AutoField(primary_key=True,
> db_column='IDFLCustomerNum') # Field name made lowercase.
>     typenum = models.IntegerField(null=True, db_column='TypeNum',
> blank=True) # Field name made lowercase.
>     type = models.CharField(max_length=255, db_column='Type',
> blank=True) # Field name made lowercase.
>     billto = models.IntegerField(null=True, db_column='BillTo',
> blank=True) # Field name made lowercase.
>
> #The contacts table that works
> class Tblcontacts(models.Model):
>     contactnumber = models.AutoField(primary_key=True,
> db_column='ContactNumber') # Field name made lowercase.
>     clientid = models.ForeignKey(Customers, db_column='ClientID') #
> Field name made lowercase.
>     contactname = models.CharField(max_length=50,
> db_column='ContactName', blank=True) # Field name made lowercase.
>     title = models.CharField(max_length=50, db_column='Title',
> blank=True) # Field name made lowercase.
>     salutation = models.CharField(max_length=50,
> db_column='Salutation', blank=True) # Field name made lowercase.
>
> Thank you for all past and future help
>
> Greg
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Empty [] using objects.all() on legacy database

2009-06-18 Thread geraldcor

Hello all,

I am trying to work with a legacy database and I ran inspectdb and
have a model with the 2 tables that I want to use. The first table,
the main table is not working at all. The second table which is
related via a foreign key seems to be working just fine. Here are the
symptoms:

In the shell I import my tables, to c=Customers.objects.all()
c
[] which is an empty dictionary or tuple (sorry for the confusion)

however if I do t=Tblcontacts.objects.all()
t
[big long list of Tblcontacts objects] and I can even utilize this
data in a template via a view.

I can't figure out why one would work while the other does not.

here are the first view field definitions in my model in case that
offers any insight.

#The customers table that doesn't work.
class Customers(models.Model):
idflcustomernum = models.AutoField(primary_key=True,
db_column='IDFLCustomerNum') # Field name made lowercase.
typenum = models.IntegerField(null=True, db_column='TypeNum',
blank=True) # Field name made lowercase.
type = models.CharField(max_length=255, db_column='Type',
blank=True) # Field name made lowercase.
billto = models.IntegerField(null=True, db_column='BillTo',
blank=True) # Field name made lowercase.

#The contacts table that works
class Tblcontacts(models.Model):
contactnumber = models.AutoField(primary_key=True,
db_column='ContactNumber') # Field name made lowercase.
clientid = models.ForeignKey(Customers, db_column='ClientID') #
Field name made lowercase.
contactname = models.CharField(max_length=50,
db_column='ContactName', blank=True) # Field name made lowercase.
title = models.CharField(max_length=50, db_column='Title',
blank=True) # Field name made lowercase.
salutation = models.CharField(max_length=50,
db_column='Salutation', blank=True) # Field name made lowercase.

Thank you for all past and future help

Greg
--~--~-~--~~~---~--~~
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: Form Wizard and Saving to Database

2009-05-19 Thread geraldcor

So that's how that works. Brilliant. Thank you. It worked perfectly.

On May 19, 1:43 am, George Song  wrote:
> On 5/18/2009 4:01 PM, geraldcor wrote:
>
> > Hello all,
>
> > I am working on my second Django app and it involves a very long form.
> > I successfully used modelForms in my last app to successfully save
> > form data to a database.
>
> > With this long form, I have split it up into smaller forms (forms.Form
> > not ModelForms) and used the FormWizard to tie it all together. All is
> > well so far. However, now I have no idea how to save the form data
> > from form_list into my database. It is only one table so I don't have
> > any foreign key stuff going on. I just need to save the form data and
> > move on with my life :)
>
> > I have searched the Django site and web extensively and haven't found
> > anything useful about saving data from regular forms or FormWizards.
>
> Just instantiate a new Model object with the form attributes assigned to
> the proper model attributes, and save the object. If you happen to name
> your form fields the same as your model fields, then you can just use
> cleaned_data directly:
>
> {{{
> form_data = {}
> for form in form_list:
>      form_data.update(form.cleaned_data)
> m = Model.objects.create(**form_data)
>
> }}}
>
> --
> George
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Form Wizard and Saving to Database

2009-05-18 Thread geraldcor

Hello all,

I am working on my second Django app and it involves a very long form.
I successfully used modelForms in my last app to successfully save
form data to a database.

With this long form, I have split it up into smaller forms (forms.Form
not ModelForms) and used the FormWizard to tie it all together. All is
well so far. However, now I have no idea how to save the form data
from form_list into my database. It is only one table so I don't have
any foreign key stuff going on. I just need to save the form data and
move on with my life :)

I have searched the Django site and web extensively and haven't found
anything useful about saving data from regular forms or FormWizards.

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