hasNoProfanities validator - no longer exists?

2011-10-06 Thread robinne
I've finally managed to get a basic validator to work on a model (I
used validate_slug on a model field and was able to catch it as a
ValidationError). After getting that to work I tried to then get the
validator that I actually want to work, hasNoProfanities. I have found
that the validator no longer exists. I think the Django 1.3 docs need
to be updated but before I request that I wanted to be sure that this
is the case. This is from the docs:


https://docs.djangoproject.com/en/1.3/ref/settings/

PROFANITIES_LIST

Default: () (Empty tuple)

A tuple of profanities, as strings, that will trigger a validation
error when the hasNoProfanities validator is called.


I guess you have to basically handle this on your own now, is that
true?

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



@transaction.commit_on_success, not getting expected results

2011-10-05 Thread robinne
Based on Django 1.3 documentation for transactions, it seems you can
have all or nothing updates of database calls within a view. I am not
getting the expected behavior and it seems there must be an
"autocommit" global setting somewhere that I need to set to false.
Does anyone know of such a setting? Here is sample code, I would
expect no updates to my "Credit" table, yet I get one new row.

@transaction.commit_on_success
def Test(request):
try:
member = request.user.get_profile()
Credit.objects.create(CreditDate=datetime.datetime.now(),
Member=member, CreditAmount=25)
Credit.objects.create(CreditDate=datetime.datetime.now(),
Member=member, CreditAmount=25.0) #FAIL

return render_to_response("Test.html")
except(Exception),e:
WriteToLog('error in test: ' + e.__str__())
return HttpResponseServerError('error')

Do I need to use @transaction.commit_manually instead? I know that
gives me the expected results but is a lot more work to update all my
code with manual commits and rollbacks. 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.



Django 1.3 logging, how to log INFO to file1.log and ERROR to file2.log

2011-10-02 Thread robinne
I want to log ERRORs to an error log and INFO to an info log file. I
have it setup like this, but the info log files gets both INFO and
ERROR logging (because it allows INFO and above severity). How do I
only run a handler for INFO and not higher items such as ERROR.

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %
(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
},
'log_errors':{
'level':'ERROR',
'class' : 'logging.handlers.RotatingFileHandler',
'filename' : os.path.join(SITEROOT, 'Logs/errors.log'),
'formatter' : 'verbose',
'backupCount' :'5',
'maxBytes' : '500'
},
'log_info':{
'level':'INFO',
'class' : 'logging.handlers.RotatingFileHandler',
'filename' : os.path.join(SITEROOT, 'Logs/info.log'),
'formatter' : 'simple',
'backupCount' :'5',
'maxBytes' : '500'
}
},
'loggers': {
'django': {
'handlers':['null'],
'propagate': True,
'level':'INFO',
},
'django.request': {
'handlers': ['log_errors'],
'level': 'ERROR',
'propagate': False,
},
'':{
'handlers': ['log_errors', 'log_info'],
'level': 'INFO',
'propagate': False,
}

}
}

-- 
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 1.3 logging, django.request logger not processed

2011-10-02 Thread robinne
I have setup my application to use the settings from the django
documentation on logging, with a few items removed for simplicity. I
have found that the logger django.request is not running even though I
am trying to log an error from within a view. If I add  '' logger
(thanks to some other posts found here), that logger will run a
handler. What am I missing with the default django.request logger?

#settings
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %
(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
},
'log_it':{
'level':'ERROR',
'class' : 'logging.handlers.RotatingFileHandler',
'filename' : os.path.join(SITEROOT, 'MYLOGGING.log'),
'formatter' : 'verbose',
'backupCount' :'5',
'maxBytes' : '500'
}
},
'loggers': {
'django': {
'handlers':['null'],
'propagate': True,
'level':'INFO',
},
'django.request': {
'handlers': ['log_it'],
'level': 'ERROR',
'propagate': False,
},
'':{
'handlers': ['log_it'],
'level': 'ERROR',
'propagate': False,
}


}
}


and the view...

import logging
logger = logging.getLogger(__name__)

def FAQ(request):
logger.error('test logging error')
return render_to_response("FAQ.html",
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-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.



Extend User model, want additional inline editing for the extended model

2011-06-13 Thread robinne
I have extended the django user model with a "Member" model. I would
like to be able to administer (on admin site) the user - all data from
both models. I need the email and name from User, but everything else
is from "Member". I have set it up so that I can get all the data on
one form, but I cannot continue to add related (child) information to
the "Member" as I typically would if it was not being displayed as an
inline model of user. Here is my attempt at doing this. It currently
works to show User + Member, but cannot show SaleItems (for a Member).

from DjangoSite.ManageProducts.models import Member, SaleItem
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.admin import User

# cannot view this data from SaleItem model
class MemSalesInline(admin.TabularInline):
model = SaleItem
fk_name = 'Seller'

class MemberProfileInline(admin.StackedInline):
model = Member
fk_name = 'user'
# this does not work
inlines = [
MemSalesInline,
]

class MyUserAdmin(UserAdmin):
inlines = [MemberProfileInline,]

try:
admin.site.unregister(User)
except admin.sites.NotRegistered:
pass

admin.site.register(User, MyUserAdmin)

-- 
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: Template inheritance, how to render dynamic content in base templates

2011-05-13 Thread robinne
Ok, thanks everyone for the replies. I will take a look at these
suggestions.

On May 13, 6:06 am, Michal Petrucha <michal.petru...@ksp.sk> wrote:
> On Thu, May 12, 2011 at 08:15:59PM -0700, robinne wrote:
> > How can I render dynamic content in a base template if I only call a
> > view on my child template?
>
> > What I am trying to do is setup a base template that will include
> > "Profile" information for the user who is logged in, for example:
> > "Welcome John", instead of "login here", on every page. But if I call
> > my child page "/Home" (for example) and it extends "base.html", how do
> > I render the dynamic content within base.html? Thanks.
>
> You can use either custom template tags as suggested by others. The
> alternative is to create custom context processors that will add
> dynamic data you want to display into the context. Then you can use it
> even in your base template. However, you'll have to make sure each
> view uses a RequestContext when rendering templates in order for the
> context processors to be applied.
>
> As for the specific problem you're solving, RequestContext already
> contains user data which means you don't need anything extra. Just
> check in your base template if a user is logged in and show his
> username if yes or a login link otherwise.
>
> Michal
>
>  signature.asc
> < 1KViewDownload

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



Template inheritance, how to render dynamic content in base templates

2011-05-12 Thread robinne
How can I render dynamic content in a base template if I only call a
view on my child template?

What I am trying to do is setup a base template that will include
"Profile" information for the user who is logged in, for example:
"Welcome John", instead of "login here", on every page. But if I call
my child page "/Home" (for example) and it extends "base.html", how do
I render the dynamic content within base.html? 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.



Re: Would django affect where or how I set ServerAdmin (apache) environment variable?

2010-10-23 Thread robinne
Contacted my VPS host. They must change this environment variable.
Sorry. Thanks.

On Oct 23, 7:37 pm, robinne <develo...@computer-shoppe.net> wrote:
> Hi,
>
> I am posting an apache question to the django users groups since I
> have django installed using wsgi and wondering if it might be
> affecting how or where I should set this environment variable.
>
> I am trying to update the email address in the 500 Internal Server
> Error message: "Please contact the server administrator,
> webmas...@localhost and inform..."
>
> I have tried to set the ServerAdmin variable in two separate config
> files, but neither change will update the error page.
> I have tried each of these in /etc/apache2/httpd.conf and /etc/apache2/
> apache2.conf (I have restarted apache after each change)
>
> ServerAdmin "m...@myemail.com"
> ServerAdmin m...@myemail.com
>
> Sorry if this is not django related at 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.



Would django affect where or how I set ServerAdmin (apache) environment variable?

2010-10-23 Thread robinne
Hi,

I am posting an apache question to the django users groups since I
have django installed using wsgi and wondering if it might be
affecting how or where I should set this environment variable.

I am trying to update the email address in the 500 Internal Server
Error message: "Please contact the server administrator,
webmas...@localhost and inform..."

I have tried to set the ServerAdmin variable in two separate config
files, but neither change will update the error page.
I have tried each of these in /etc/apache2/httpd.conf and /etc/apache2/
apache2.conf (I have restarted apache after each change)

ServerAdmin "m...@myemail.com"
ServerAdmin m...@myemail.com

Sorry if this is not django related at 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.



trying to do console testing of my models, "no module named X"

2010-06-23 Thread robinne
I have a django project running on local linux machine with apache. I
run this at localhost:8081 and I use import statements to import my
models in my views (e.g. "from DjangoSite.ManageProducts.models import
Member").

For testing, I want to be able to import my models into python console
and run test queries. I don't know how python knows where my models
are...when I run import statement in python console, it comes back
with error "no module named DjangoSite.ManageProducts.models".

How do I references my own modules using console? Do I need to add my
project to python path?

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



Re: Upload image file, resize using PIL, then save into ImageField - what to save to ImageField?

2010-03-19 Thread robinne
Thanks for all your replies. I ended up using sorl-thumbnail, which I
had already installed, but I didn't think it kept aspect ratio of
image because you are required to enter w and h for thumbnail image
size using ThumbnailField. A quick test shows that it resizes and
keeps same aspect ratio. So, I am able to upload a file and save it to
a ThumbnailField as smaller version, which is all I needed. Thanks!

On Mar 18, 7:03 am, Alex Robbins <alexander.j.robb...@gmail.com>
wrote:
> I think Satchmo useshttp://code.google.com/p/sorl-thumbnail/
> I think it uses PIL underneath a layer of abstraction. That might work
> for you if you are just wanting to generate alternate versions of
> uploaded images.
>
> Alex
>
> On Mar 18, 12:10 am, robinne <develo...@computer-shoppe.net> wrote:
>
> > I can save an uploaded image to a FileField like this (where
> > "ProductFile" is a model) and "TempFile" is an ImageField:
>
> > uploadedfile = request.FILES['uploadfile']
> > ProductFile.objects.create(FileName=UploadDate=datetime.datetime.now(),
> > TempFile=uploadedfile)
>
> > But, how do I manipulate the image size and then save to this model? I
> > am working with PIL, but I can't save a PIL Image to a ImageField. Can
> > I save the file to disk using PIL and then pass in the file path and
> > name to the model? If so, what is the syntax for saving the ImageFile
> > when you are no longer working with the original uploadedfile object?

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



Upload image file, resize using PIL, then save into ImageField - what to save to ImageField?

2010-03-17 Thread robinne
I can save an uploaded image to a FileField like this (where
"ProductFile" is a model) and "TempFile" is an ImageField:

uploadedfile = request.FILES['uploadfile']
ProductFile.objects.create(FileName=UploadDate=datetime.datetime.now(),
TempFile=uploadedfile)

But, how do I manipulate the image size and then save to this model? I
am working with PIL, but I can't save a PIL Image to a ImageField. Can
I save the file to disk using PIL and then pass in the file path and
name to the model? If so, what is the syntax for saving the ImageFile
when you are no longer working with the original uploadedfile object?

-- 
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: Returning array of integers as part of json dump, how to access in Javascript

2010-02-14 Thread robinne
Yea, that was it. I guess I wasn't quite clear on what was getting
passed back from the ajax call. I didn't realize obj.PythonList was
already a javascript array.

Thanks for your response, sorry my code wasn't very clear.

On Feb 13, 3:10 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> Unfortunately your question is not clear, and this "clarification"
> does not really help matters. As far as I can tell, obj.PythonList is
> already an array. If you do:
>    jArray = [obj.PythonList]
> then yes, jArray[0] is indeed the whole contents of obj.PythonList.
> But I don't understand why you want to do this - why not just
> obj.PythonList[0] which should be 3?
> --
> DR.
>
> On Feb 13, 7:04 pm, robinne <develo...@computer-shoppe.net> wrote:
>
> > I put in wrong variable name:
>
> > > var PIDS = obj.PackageIDS; //this brings back 3,2 for example, an
> > > array of integers.
>
> > should be...
>
> > var PIDS = obj.PythonList;
>
> > On Feb 13, 10:10 am, robinne <develo...@computer-shoppe.net> wrote:
>
> > > I am trying to pass an array of integers from a view to javascript in
> > > an ajax call.
>
> > > I know how to return json dump from a View so that javascript can
> > > access it as an object like this:
>
> > > VIEW
> > > response_dict = {"PythonList": MyList, "EditType": edittype}
> > > return HttpResponse(simplejson.dumps(response_dict), mimetype='text/
> > > javascript')
>
> > > where MyList is a... python list created by:
> > > MyList = []
> > >             for p in packages:
> > >                 MyList.append(p.id)
>
> > > in javascript, I can access the json by:
> > > var obj = YAHOO.lang.JSON.parse(o.responseText);
> > > var PIDS = obj.PackageIDS; //this brings back 3,2 for example, an
> > > array of integers.
>
> > > I cannot get at PIDS as an array in javascript. When I try to convert
> > > to an array, the first item in the array is always all values (3,2)
> > > instead of just the first one (3). The most simplistic attempt at this
> > > was:
>
> > > var jArray = [obj.PythonList]
>
> > > Any suggestions?

-- 
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: Returning array of integers as part of json dump, how to access in Javascript

2010-02-13 Thread robinne
I put in wrong variable name:

> var PIDS = obj.PackageIDS; //this brings back 3,2 for example, an
> array of integers.

should be...

var PIDS = obj.PythonList;


On Feb 13, 10:10 am, robinne <develo...@computer-shoppe.net> wrote:
> I am trying to pass an array of integers from a view to javascript in
> an ajax call.
>
> I know how to return json dump from a View so that javascript can
> access it as an object like this:
>
> VIEW
> response_dict = {"PythonList": MyList, "EditType": edittype}
> return HttpResponse(simplejson.dumps(response_dict), mimetype='text/
> javascript')
>
> where MyList is a... python list created by:
> MyList = []
>             for p in packages:
>                 MyList.append(p.id)
>
> in javascript, I can access the json by:
> var obj = YAHOO.lang.JSON.parse(o.responseText);
> var PIDS = obj.PackageIDS; //this brings back 3,2 for example, an
> array of integers.
>
> I cannot get at PIDS as an array in javascript. When I try to convert
> to an array, the first item in the array is always all values (3,2)
> instead of just the first one (3). The most simplistic attempt at this
> was:
>
> var jArray = [obj.PythonList]
>
> Any suggestions?

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



Returning array of integers as part of json dump, how to access in Javascript

2010-02-13 Thread robinne
I am trying to pass an array of integers from a view to javascript in
an ajax call.

I know how to return json dump from a View so that javascript can
access it as an object like this:

VIEW
response_dict = {"PythonList": MyList, "EditType": edittype}
return HttpResponse(simplejson.dumps(response_dict), mimetype='text/
javascript')

where MyList is a... python list created by:
MyList = []
for p in packages:
MyList.append(p.id)

in javascript, I can access the json by:
var obj = YAHOO.lang.JSON.parse(o.responseText);
var PIDS = obj.PackageIDS; //this brings back 3,2 for example, an
array of integers.

I cannot get at PIDS as an array in javascript. When I try to convert
to an array, the first item in the array is always all values (3,2)
instead of just the first one (3). The most simplistic attempt at this
was:

var jArray = [obj.PythonList]

Any suggestions?

-- 
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: request.POST['value'] cannot get value, 500 error

2009-11-11 Thread robinne
Thanks. I tried a lot of different options but nothing was working.
Finally got it working with this:

req = request.POST['value']#this is how InputEx sends it, with root =
value.
parsedRequest = simplejson.loads(req)
print parsedRequest["Username"]

Basically, I got the array of 'value', then turned that into JSON and
then read from that.

On Nov 10, 11:06 pm, Tamas Szabo <szab...@gmail.com> wrote:
> Does
>
> request.POST['value'][0]['LastName']
>
> work?
>
> It looks like your post data has an array (keyed as 'value') of dicts.
>
> You might also consider using Firebug (or something similar) to inspect the
> http requests and responses when you are developing.
>
> Regards,
>
> Tamas
>
> On Wed, Nov 11, 2009 at 2:38 PM, robinne <develo...@computer-shoppe.net>wrote:
>
>
>
> > I am posting data from a form to a django view. The form is created
> > using inputEx (a YUI-like interface). The form gets created much like
> > you create a YUI form and you include names for all your fields in
> > javascript. It is javascript that creates the form on the page.
>
> > I am able to load database data from the django view into my form
> > fields (sending json string to UI), but when I post I cannot access
> > individual posted values, even though I can see that the
> > 'request.POST' is getting posted to the django view. The request.POST
> > looks something like <QueryDict:{u'value':
> > [u'{"FirstName":"Mary","LastName":"Smith"...etc]}>
>
> > When trying to access a value by using...
>
> > def MemberInfo(request, member_id):
> >    if request.method == "POST":
> >        print request.POST
> >        try:
> >            print request.POST['LastName'] #ERROR
>
> > ...
> > error message is:
> >  "POST /MemberInfo/1 HTTP/1.1" 500 54476
>
> > any ideas?

--

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




request.POST['value'] cannot get value, 500 error

2009-11-10 Thread robinne

I am posting data from a form to a django view. The form is created
using inputEx (a YUI-like interface). The form gets created much like
you create a YUI form and you include names for all your fields in
javascript. It is javascript that creates the form on the page.

I am able to load database data from the django view into my form
fields (sending json string to UI), but when I post I cannot access
individual posted values, even though I can see that the
'request.POST' is getting posted to the django view. The request.POST
looks something like 

When trying to access a value by using...

def MemberInfo(request, member_id):
if request.method == "POST":
print request.POST
try:
print request.POST['LastName'] #ERROR

...
error message is:
 "POST /MemberInfo/1 HTTP/1.1" 500 54476

any ideas?


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



Can't use ModelForm, basic template and ajax to submit a form, over and over...can I?

2009-11-01 Thread robinne

I'm giving up on something I was so close to getting to work...just
want to make sure there isn't a simple solution. I have  ModelForm and
I have a simple template that iterates and creates the form fields. I
update the form using YUI.io ajax submit. It works great. I am able to
post the data to the database using ajax and the form fields are now
updated with the new data. The problem is, subsequent posts will not
submit any new data entered. It has lost knowledge of the form or
something (the form and it's id is not regenerated from the ajax call,
but the form fields are). I have my code posted here
http://stackoverflow.com/questions/1655486/yui-io-ajax-and-django-update-works-only-once-yui-cant-find-form-again

Any advice is appreciated. I am now going to hand code all fields and
use json to manually handle every field (ugh, there goes all that
django was providing me).
--~--~-~--~~~---~--~~
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: ModelForm - how to post primary key to update existing record?

2009-10-26 Thread robinne

I pass Member to the template with something like this...(I don't have
my code here with me)

VIEW
...
if not post
  member = MemberModel(pk=1)
  return render_to_response('mytemplate.html', {'Member':member})

Basically, I am providing a Member (ModelForm) to the template.

What you gave me here should help, I was not familiar with additional
parameters, I will
look more into that.  I just thought I needed the posted data and it
would include the primary key
and then I could load that member again and pass to the save routine.

Thank you!

On Oct 26, 4:07 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Oct 26, 5:19 am, robinne <develo...@computer-shoppe.net> wrote:
>
>
>
> > I am noticing that when I load an existing ModelForm into a template,
> > and I save (POST), I can't seem to get the primary key back in order
> > to update that specific record. I am starting to head down the path of
> > formsets...but that is not what I need. I am updating one record only.
> > Any help is appreciated!
>
> > VIEW
> > def UpdateMember(request):
> >   if request.method == "POST":
> >    # I don't seem to have access to primary key...
> >    # I do have the posted data, and can save to database here.
>
> > TEMPLATE (as you can see, I've tried to explicitly include primary
> > key, both inside and outside the for loop)
> >  {{ Member.MemberID }}
> >  {% for field in Member %}
> >  {{ field.label_tag }}
> >  {{ field }}
> >  {% endfor %}
> > 
>
> You haven't posted the code that shows how you instantiate the form.
> Clearly your UpdateMember view must be taking more than just the
> request parameter - it must include a parameter that gets the object
> you want to update in the first place. And when you instantiate the
> form for editing, you must be passing the 'instance' parameter, so you
> get the data for the form to update. So all you need to do on POST is
> to use that parameter again.
>
> def update_member(request, pk):
>     member = get_object_or_404(member, pk=pk)
>     if request.POST:
>         form = MyForm(instance=member, data=request.POST)
>         if form.is_valid():
>             form.save()
>             return HttpResponseRedirect('/wherever/')
>     else:
>         form = MyForm(instance=member)
>
>     return render_to_response('mytemplate.html', {'form':form})
>
> --
> DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ModelForm - how to post primary key to update existing record?

2009-10-25 Thread robinne

I am noticing that when I load an existing ModelForm into a template,
and I save (POST), I can't seem to get the primary key back in order
to update that specific record. I am starting to head down the path of
formsets...but that is not what I need. I am updating one record only.
Any help is appreciated!

VIEW
def UpdateMember(request):
  if request.method == "POST":
   # I don't seem to have access to primary key...
   # I do have the posted data, and can save to database here.


TEMPLATE (as you can see, I've tried to explicitly include primary
key, both inside and outside the for loop)
 {{ Member.MemberID }}
 {% for field in Member %}
 {{ field.label_tag }}
 {{ field }}
 {% endfor %}

--~--~-~--~~~---~--~~
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: One to Many on Template UI

2009-10-07 Thread robinne

Wow, that worked, thank you! I thought I had tried everything. I was
able to loop child items on the UI template with {% for item in
mymembers.products_set.all %} ...

On Oct 6, 9:54 pm, hcarvalhoalves <hcarvalhoal...@gmail.com> wrote:
> On 7 out, 01:23, robinne <develo...@computer-shoppe.net> wrote:
>
> > I have my model setup with foreign key relationships. I can read one
> > table's data to the UI. But I cannot figure out how to read child
> > records onto template. I know it is (in the case of Blog, Author, and
> > Entry) b.entry_set.all(). But I don't know where this code goes. It
> > won't work in the template in a for each loop and I'm not sure how to
> > set it in the view.
>
> > my view:
>
> > mymembers = Members.objects.all()
>
> > then I return mymembers to the UI.
>
> > Please help with where I need to code the 'class'_set.all() this so
> > that I can get to child records on template UI. Thanks!
>
> No problem. You can access properties and methods from the template,
> like this:
>
> {{ b.entry_set.all }}
>
> Keep in mind that this is limited for properties and methods without
> arguments only.
> Doing something like the following doesn't work:
>
> {{ b.entry_set.filter(nickname='newbie') }}
>
> If you find coding too much logic on templates, better you process the
> values on the view
> and pass in the context, or abstract this logic in your domain model.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



One to Many on Template UI

2009-10-06 Thread robinne

I have my model setup with foreign key relationships. I can read one
table's data to the UI. But I cannot figure out how to read child
records onto template. I know it is (in the case of Blog, Author, and
Entry) b.entry_set.all(). But I don't know where this code goes. It
won't work in the template in a for each loop and I'm not sure how to
set it in the view.

my view:

mymembers = Members.objects.all()

then I return mymembers to the UI.

Please help with where I need to code the 'class'_set.all() this so
that I can get to child records on template UI. 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
-~--~~~~--~~--~--~---



Re: Cannot display images - need help with settings for development environment

2009-08-22 Thread robinne

I figured it out:

#MEDIA_URL = 'http://localhost:8000/testproject/site_media/'

MEDIA_URL = '/site_media/'

On Aug 22, 8:57 am, robinne <develo...@computer-shoppe.net> wrote:
> I'm new to Django and I cannot seem to get all the settings correct to
> allow me to view images in the development environment. Here is what I
> know (I'm developing on Vista):
>
> For internal server to serve images, you have to configure django
> settings, so here is what I've done.
> [My actual path to images is: c:\django\testproject\petinfostore
> \myimages]
> [The URL I want to use ishttp://localhost:8000/testproject/site_media/
>
> My Settings are:
>
> MEDIA_URL = 'http://localhost:8000/testproject/site_media/'
> MEDIA_ROOT = 'c:/django/testproject/petinfostore/myimages' (I've also
> tried backslashes)
>
> INSTALLED_APPS = (
>    ...
>     'django.views.static',
> )
>
> urlpatterns includes:
>  (r'^site_media/(?P.*)$', 'django.views.static.serve',
>     {'document_root': 'c:/django/testproject/petinfostore/myimages'}),
>
> When my page displays, the url to the image that is supposed to
> display is:
> 
>
> Any help is appreciated. 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
-~--~~~~--~~--~--~---



Cannot display images - need help with settings for development environment

2009-08-22 Thread robinne

I'm new to Django and I cannot seem to get all the settings correct to
allow me to view images in the development environment. Here is what I
know (I'm developing on Vista):

For internal server to serve images, you have to configure django
settings, so here is what I've done.
[My actual path to images is: c:\django\testproject\petinfostore
\myimages]
[The URL I want to use is http://localhost:8000/testproject/site_media/

My Settings are:

MEDIA_URL = 'http://localhost:8000/testproject/site_media/'
MEDIA_ROOT = 'c:/django/testproject/petinfostore/myimages' (I've also
tried backslashes)

INSTALLED_APPS = (
   ...
'django.views.static',
)

urlpatterns includes:
 (r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': 'c:/django/testproject/petinfostore/myimages'}),

When my page displays, the url to the image that is supposed to
display is:


Any help is appreciated. 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
-~--~~~~--~~--~--~---