djngo unittest to use "real" database.

2020-09-06 Thread django-newbie
Hi All,

I am currently writing test cases for views, Which eventually uses database 
also.
By default a test database is being created and removed after test are run.

As the database itself is development database, I don't want my test to 
create a separate db but use exciting only.
Also I will like to bring to your notice, that in my environment, database 
are created and provided and django can't run migration or create database.

Regards,
Arjit 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e6fd0155-ee4e-46f7-8e81-74983d388536n%40googlegroups.com.


Re: How models.Manager is working behind the scene and calling different serialize methods?

2020-05-29 Thread django-newbie
Ohk, I got it now..
Thanks for clarifying this.

My further doubts in continuation of this are.

1. For confirmation, ModelName.objects.all() calls get_queryset() method, 
while ModelName.objects.get calls get() method internally.

2. In above code to override default serialize method of BasicUserUpdate 
for get_queryset() method, 
We have to do 2 things.
1. Inherit default models.Manager and override get_queryset() method.
2. Inherit  models.QuerySet and override default serialize method.

Honestly it seems overkill for this problem.
Can u please suggest alternative straight forward way to do it in model 
only.

On Friday, May 29, 2020 at 3:34:39 PM UTC+5:30, Sencer Hamarat wrote:
>
> I believe, the method "get_query*set*" name is explains what you want to 
> know.
>
> If you filter or fetch every thing with django query, it returns queryset.
> The .get() query on the other hand, returns a single object.
>
> Saygılarımla,
> Sencer HAMARAT
>
>
>
> On Fri, May 29, 2020 at 4:43 AM django-newbie  > wrote:
>
>> Hi, 
>> I am new to django and going through a tutorial and now confused with one 
>> particular implementation.
>>
>> models.py
>>
>> import json
>> from django.core.serializers import serialize
>>
>> from django.db import models
>> from django.conf import settings
>>
>> # Create your models here.
>>
>>
>> def upload_update_image(instance, filename):
>> return "updates/{owner}/{filename}".format(owner=instance.owner, 
>> filename=filename)
>>
>> class UpdateQuerySet(models.QuerySet):
>>  
>> def serialize(self):
>> print("UpdateQuerySet serialize")
>> print(self.values("owner", "content", "image"))
>> list_values = list(self.values("owner", "content", "image"))
>> return json.dumps(list_values)
>>
>>
>> class UpdateManager(models.Manager):
>>
>> def get_queryset(self):
>> print('get_queryset method')
>> return UpdateQuerySet(self.model, using=self._db)
>>
>>
>> class BasicUserUpdate(models.Model):
>> owner = 
>> models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
>> content = models.TextField(blank=True,null=True)
>> image = 
>> models.ImageField(blank=True,null=True,upload_to=upload_update_image,)
>> updated = models.DateTimeField(auto_now=True)
>> timestamp = models.DateTimeField(auto_now_add=True)
>>
>> def __str__(self):
>> return self.content or ''
>>
>> objects = UpdateManager()
>>
>>
>> def serialize(self):
>> print("BasicUserUpdate serialize")
>> try:
>> image = self.image.url
>> except:
>> image = ""
>> data = {
>> "content": self.content,
>> "owner": self.owner.id,
>> "image": image
>> }
>> data = json.dumps(data)
>> return data
>>
>>   
>> views.py
>>
>> from basic.models import BasicUserUpdate
>> from django.views import View
>> from django.http import HttpResponse
>>
>>
>> class BasicUserUpdateListView(View):
>> def get(self, request, *args, **kwargs):
>> qs = BasicUserUpdate.objects.all()
>> json_data = qs.serialize()
>> return HttpResponse(json_data, content_type='application/json')
>>
>> class BasicUserUpdateDetailView(View):
>>
>> def get(self, request,id, *args, **kwargs):
>> qs = BasicUserUpdate.objects.get(id=id)
>> json_data = qs.serialize()
>> return HttpResponse(json_data, content_type='application/json')
>>
>> ]
>>
>>
>> *At run time calling ListView, get below print messages*
>> get_queryset method
>> UpdateQuerySet serialize
>>
>> *At run time calling DetailView, get below print messages*
>> get_queryset method
>> BasicUserUpdate serialize
>>
>>
>> *How Django is identifying which serialize method to be called? *
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/3fdc04cb-5da9-4d6a-8935-3ebf9409196b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/3fdc04cb-5da9-4d6a-8935-3ebf9409196b%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/560f2715-eae2-4dd7-9172-f71acd5368d7%40googlegroups.com.


How models.Manager is working behind the scene and calling different serialize methods?

2020-05-28 Thread django-newbie
Hi, 
I am new to django and going through a tutorial and now confused with one 
particular implementation.

models.py

import json
from django.core.serializers import serialize

from django.db import models
from django.conf import settings

# Create your models here.


def upload_update_image(instance, filename):
return "updates/{owner}/{filename}".format(owner=instance.owner, 
filename=filename)

class UpdateQuerySet(models.QuerySet):
 
def serialize(self):
print("UpdateQuerySet serialize")
print(self.values("owner", "content", "image"))
list_values = list(self.values("owner", "content", "image"))
return json.dumps(list_values)


class UpdateManager(models.Manager):

def get_queryset(self):
print('get_queryset method')
return UpdateQuerySet(self.model, using=self._db)


class BasicUserUpdate(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
content = models.TextField(blank=True,null=True)
image = 
models.ImageField(blank=True,null=True,upload_to=upload_update_image,)
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.content or ''

objects = UpdateManager()


def serialize(self):
print("BasicUserUpdate serialize")
try:
image = self.image.url
except:
image = ""
data = {
"content": self.content,
"owner": self.owner.id,
"image": image
}
data = json.dumps(data)
return data

  
views.py

from basic.models import BasicUserUpdate
from django.views import View
from django.http import HttpResponse


class BasicUserUpdateListView(View):
def get(self, request, *args, **kwargs):
qs = BasicUserUpdate.objects.all()
json_data = qs.serialize()
return HttpResponse(json_data, content_type='application/json')

class BasicUserUpdateDetailView(View):

def get(self, request,id, *args, **kwargs):
qs = BasicUserUpdate.objects.get(id=id)
json_data = qs.serialize()
return HttpResponse(json_data, content_type='application/json')

]


*At run time calling ListView, get below print messages*
get_queryset method
UpdateQuerySet serialize

*At run time calling DetailView, get below print messages*
get_queryset method
BasicUserUpdate serialize


*How Django is identifying which serialize method to be called? *

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3fdc04cb-5da9-4d6a-8935-3ebf9409196b%40googlegroups.com.


Recommend a way to add my own class into DjanGo

2012-10-17 Thread Django Newbie
Hey guys,

I want to create a custom class with methods I will be able to access 
everywhere in my Views.

For example a class that add numbers after declaring it somewhere in 
Django. 
*MyNumber = new GenNumberClass()*
*MyNumber.setNumbers(1,2)*
*result = MyNumber.getAddedResult()*

Please point me in the right direction where I can declare classes and 
reuse them. Any recommendations will be welcome.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/dHGOSKJe-GcJ.
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: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Another Django Newbie


On Wednesday, March 21, 2012 10:29:48 AM UTC, Jani Tiainen wrote:
>
> Like this:
>
> 'default': {
>'ENGINE': '...',
>'OPTIONS': {
>   'threaded': True
>}
> }
>

Thanks again Jani, switching my question to the modwsgi group 

Regards, ADN
 

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Whpuuwt22WEJ.
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: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Another Django Newbie


On Wednesday, March 21, 2012 7:18:16 AM UTC, Jani Tiainen wrote:
>
> 20.3.2012 16:45, Another Django Newbie kirjoitti:
> >
> >
> > On Tuesday, March 20, 2012 10:28:49 AM UTC, Another Django Newbie wrote:
> >
> >
> >
> > On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:
> >
> > On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen 
> > wrote:
> >  > Hi,
> >  >
> >  > Since we use same setup except one part: we use mod_wsgi
> > instead of
> >  > mod_fcgi.
> >  >
> >  > (Since wsgi is considered to be defacto protocol). Could you
> > try to use it?
> >  >
> >
> > WSGI is the de-facto for hosting python in web servers. If you
> > aren't
> > running just python, it's nice to use the same hosting mechanism 
> for
> > all your apps, and fastcgi is a supported mechanism.
> >
> > OP: You mention using mod_fcgid, but you do not give us any idea 
> of
> > how you are using mod_fcgid. Configuration and error logs
> > please. FYI,
> > we run django quite happily under mod_fastcgi.
> >
> > Cheers
> >
> > Tom
> >
> >
> >
> > Hi Tom, Jani,
> >
> > Currently struggling to compile mod_wsgi, or more specifically a
> > shared library version of python - something to do with mismatched
> > 32/64 bit libraries I think.
> >
> > Here's an extract from httpd.conf.
> >
> > RewriteEngine On
> > RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]
> > 
> > Options ExecCGI
> > AddHandler fcgid-script .cgi
> > # AddHandler cgi-script .cgi
> > Require all granted
> > 
> >
> > and the relevant django.cgi
> >
> > #!/usr/local/bin/python
> > from FcgiWsgiAdapter import list_environment, serve_wsgi
> >
> > import os, sys
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
> > os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
> >
> > from django.core.handlers.wsgi import WSGIHandler
> >
> > # use this to test that fastcgi works and to inspect the environment
> > # serve_wsgi(list_environment)
> > # use this to serve django
> > serve_wsgi(WSGIHandler())
> >
> > The "FcgiWsgiAdapter" referred to came from djangosnippets.org
> > <http://djangosnippets.org/snippets/1307/>.
> >
> > As to error logs, as I mentioned in the original post I don't see
> > anything added to any logs when this happens and there is only a
> > warning about the ssl library when apache is restarted.
> >
> > Regards, ADN
> >
> >
> >
> > *So I swapped to using WSGI with this apache config *
> >
> > WSGIScriptAlias / /home/user/python/djcode/cfServer/apache/django.wsgi
> > WSGIDaemonProcess site-1 threads=30
> > WSGIProcessGroup site-1
> >
> > 
> > AllowOverride None
> > Options None
> > Require all granted
> > 
> >
> > and this django.wsgi
> >
> > import os, sys
> > sys.path.append('/home/user/python/djcode')
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
> > os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
> > os.environ['PYTHON_EGG_CACHE'] = '/var/www/.python-eggs'
> >
> > import django.core.handlers.wsgi
> >
> > application = django.core.handlers.wsgi.WSGIHandler()
> >
> > and I get segmentation faults (debug level tracing from apache error log)
> >
> > [Tue Mar 20 14:16:28.126341 2012] [core:notice] [pid 17487:tid
> > 47401308446624] AH00051: child pid 17490 exit signal Segmentation fault
> > (11), possible coredump in /tmp/apache2-gdb-dump
> > [Tue Mar 20 14:16:28.126385 2012] [:info] [pid 17487:tid 47401308446624]
> > mod_wsgi (pid=17490): Process 'site-2' has died, deregister and restart 
> it.
> > [Tue Mar 20 14:16:28.126394 2012] [:info] [pid 17487:tid 47401308446624]
> > mod_wsgi (pid=17490): Process 'site-2' has been deregistered and will no
> > longer be monitored.
> > [Tue Mar 20 14:16:28.126826 2012] [:info] [pid 17846:tid 47401308446624]
> > mod_wsgi (pid=17846): Starting process 'site-2' with uid=48, gid=48 and
> > threads=25.
> > [Tue Mar 20 14:16:28.127268 2012] [:info] [pid 17846:tid 47401308446624]
> > mod_wsgi (pid=17846): Initializing Python.
> >
> > Back trace

Re: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-20 Thread Another Django Newbie


On Tuesday, March 20, 2012 10:28:49 AM UTC, Another Django Newbie wrote:
>
>
>
> On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:
>>
>> On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen  wrote:
>> > Hi,
>> >
>> > Since we use same setup except one part: we use mod_wsgi instead of
>> > mod_fcgi.
>> >
>> > (Since wsgi is considered to be defacto protocol). Could you try to use 
>> it?
>> >
>>
>> WSGI is the de-facto for hosting python in web servers. If you aren't
>> running just python, it's nice to use the same hosting mechanism for
>> all your apps, and fastcgi is a supported mechanism.
>>
>> OP: You mention using mod_fcgid, but you do not give us any idea of
>> how you are using mod_fcgid. Configuration and error logs please. FYI,
>> we run django quite happily under mod_fastcgi.
>>
>> Cheers
>>
>> Tom
>>
>
>
> Hi Tom,  Jani,
>
> Currently struggling to compile mod_wsgi, or more specifically a shared 
> library version of python - something to do with mismatched 32/64 bit 
> libraries I think.
>
> Here's an extract from httpd.conf.
>
> RewriteEngine On
> RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]
> 
> Options ExecCGI
> AddHandler fcgid-script .cgi
> # AddHandler cgi-script .cgi
> Require all granted
> 
>
> and the relevant django.cgi
>
> #!/usr/local/bin/python
> from FcgiWsgiAdapter import list_environment, serve_wsgi
>
> import os, sys
> os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
> os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
>
> from django.core.handlers.wsgi import WSGIHandler
>
> # use this to test that fastcgi works and to inspect the environment
> # serve_wsgi(list_environment)
> # use this to serve django
> serve_wsgi(WSGIHandler())
>
> The "FcgiWsgiAdapter" referred to came from 
> djangosnippets.org<http://djangosnippets.org/snippets/1307/>
> .
>
> As to error logs, as I mentioned in the original post I don't see anything 
> added to any logs when this happens and there is only a warning about the 
> ssl library when apache is restarted.
>
> Regards, ADN
>


*So I swapped to using WSGI with this apache config *

WSGIScriptAlias / /home/user/python/djcode/cfServer/apache/django.wsgi
WSGIDaemonProcess site-1 threads=30
WSGIProcessGroup site-1


AllowOverride None
Options None
Require all granted


and this django.wsgi

import os, sys
sys.path.append('/home/user/python/djcode')
os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
os.environ['PYTHON_EGG_CACHE'] = '/var/www/.python-eggs'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

and I get segmentation faults (debug level tracing from apache error log)

[Tue Mar 20 14:16:28.126341 2012] [core:notice] [pid 17487:tid 
47401308446624] AH00051: child pid 17490 exit signal Segmentation fault 
(11), possible coredump in /tmp/apache2-gdb-dump
[Tue Mar 20 14:16:28.126385 2012] [:info] [pid 17487:tid 47401308446624] 
mod_wsgi (pid=17490): Process 'site-2' has died, deregister and restart it.
[Tue Mar 20 14:16:28.126394 2012] [:info] [pid 17487:tid 47401308446624] 
mod_wsgi (pid=17490): Process 'site-2' has been deregistered and will no 
longer be monitored.
[Tue Mar 20 14:16:28.126826 2012] [:info] [pid 17846:tid 47401308446624] 
mod_wsgi (pid=17846): Starting process 'site-2' with uid=48, gid=48 and 
threads=25.
[Tue Mar 20 14:16:28.127268 2012] [:info] [pid 17846:tid 47401308446624] 
mod_wsgi (pid=17846): Initializing Python.

Back trace on core file ...

Core was generated by `/usr/local/apache2/bin/httpd -k start'.
Program terminated with signal 11, Segmentation fault.
#0  0x0036422cb2e6 in poll () from /lib64/libc.so.6
(gdb) bt
#0  0x0036422cb2e6 in poll () from /lib64/libc.so.6
#1  0x2b1c7a05dd79 in apr_poll (aprset=0x7fff13f01e40, num=1,
nsds=0x7fff13f01e94, timeout=0) at poll/unix/poll.c:120
#2  0x2b1c7d5166d3 in wsgi_daemon_main (p=0x1257a138, daemon=0x12696218)
at mod_wsgi.c:11330
#3  0x2b1c7d51851f in wsgi_start_process (p=0x1257a138, 
daemon=0x12696218)
at mod_wsgi.c:11969
#4  0x2b1c7d518f50 in wsgi_start_daemons (pconf=0x1257a138,
ptemp=, plog=,
s=) at mod_wsgi.c:12181
#5  wsgi_hook_init (pconf=0x1257a138, ptemp=,
plog=, s=) at mod_wsgi.c:13755
#6  0x00444c2c in ap_run_post_config (pconf=0x1257a138,
plog=0x125df538, ptemp=0x125a5348, s=0x125a3508) at config.c:101
#7  0x00428734 in main (argc=3, argv=0x7fff13f02498) at main.c:765



Using WSGI briefly solved the original problem, in that I could see the 
complete admin page that was previously truncated but now nothing works - I 
ge

Re: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-20 Thread Another Django Newbie


On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:
>
> On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen  wrote:
> > Hi,
> >
> > Since we use same setup except one part: we use mod_wsgi instead of
> > mod_fcgi.
> >
> > (Since wsgi is considered to be defacto protocol). Could you try to use 
> it?
> >
>
> WSGI is the de-facto for hosting python in web servers. If you aren't
> running just python, it's nice to use the same hosting mechanism for
> all your apps, and fastcgi is a supported mechanism.
>
> OP: You mention using mod_fcgid, but you do not give us any idea of
> how you are using mod_fcgid. Configuration and error logs please. FYI,
> we run django quite happily under mod_fastcgi.
>
> Cheers
>
> Tom
>


Hi Tom,  Jani,

Currently struggling to compile mod_wsgi, or more specifically a shared 
library version of python - something to do with mismatched 32/64 bit 
libraries I think.

Here's an extract from httpd.conf.

RewriteEngine On
RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]

Options ExecCGI
AddHandler fcgid-script .cgi
# AddHandler cgi-script .cgi
Require all granted


and the relevant django.cgi

#!/usr/local/bin/python
from FcgiWsgiAdapter import list_environment, serve_wsgi

import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'

from django.core.handlers.wsgi import WSGIHandler

# use this to test that fastcgi works and to inspect the environment
# serve_wsgi(list_environment)
# use this to serve django
serve_wsgi(WSGIHandler())

The "FcgiWsgiAdapter" referred to came from 
djangosnippets.org
.

As to error logs, as I mentioned in the original post I don't see anything 
added to any logs when this happens and there is only a warning about the 
ssl library when apache is restarted.

Regards, ADN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uJNwanmADZIJ.
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: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-19 Thread Another Django Newbie


On Thursday, March 15, 2012 1:05:53 PM UTC, Another Django Newbie wrote:
>
> Hi, 
>
> I've just started playing with django this week and was following the 
> example in the Django Book. 
>
> I created an example of my own, based on the models.py in the book and 
> tested it with manage.py runserver. All worked OK, but when I try it 
> in apache one of my admin pages is truncated - a number of fields are 
> left off and there is no Save button. The exact number of fields 
> truncated depends on whether I use Add from the main page or from the 
> Add page of another field (so that the affected page is a pop-up) 
>
> Apache 2.4.1 
> mod_fcgid 2.3.6 
> django 1.3.1 
> Python 2.7.2 
> cx-Oracle 5.1.1 
>
> Has anyone seen this behaviour? I've looked in apache and django logs 
> but don't see anything recorded when the page loads. Any ideas greatly 
> appreciated. 
>
> Thanks.


Bump  I've had no luck with this and would still appreciate some 
pointers! I've tried re-arranging the order of statements in my model code 
without any improvement.




 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/asZ5sigBBuQJ.
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.



Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-15 Thread Another Django Newbie
Hi,

I've just started playing with django this week and was following the
example in the Django Book.

I created an example of my own, based on the models.py in the book and
tested it with manage.py runserver. All worked OK, but when I try it
in apache one of my admin pages is truncated - a number of fields are
left off and there is no Save button. The exact number of fields
truncated depends on whether I use Add from the main page or from the
Add page of another field (so that the affected page is a pop-up)

Apache 2.4.1
mod_fcgid 2.3.6
django 1.3.1
Python 2.7.2
cx-Oracle 5.1.1

Has anyone seen this behaviour? I've looked in apache and django logs
but don't see anything recorded when the page loads. Any ideas greatly
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.



What am I doing wrong with this URL Pattern

2012-01-27 Thread Django Newbie
Hi,

I am trying to figure out a way to call a function depending on the
parameter in the URL.

Example.
url(r'^People/Info/(?P\d+)/$', 'iFriends.People.views.details'),
url(r'^People/Info/(?P[a-z]{3})/$',
'iFriends.People.views.detail_name'),

It works with numeric value.  if I use "http://localhost:8000/
People/Info/1/"

but not with  if I use http://localhost:8000/People/Info/Jan/

probably something small but still leaning.

-- 
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: user_id in admin pages

2008-12-10 Thread Django Newbie

Found it  thanks.

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-methods

James Bennett wrote:
> On Wed, Dec 10, 2008 at 6:28 PM, Django Newbie <[EMAIL PROTECTED]> wrote:
>   
>> This is probably an easy one, but I've tried what make sense to me with
>> not success.  What I want to do is in my admin pages, use the User
>> module and enter the the user_id of whoever is logged in to add an entry
>> in one of my foreign key tables.
>> 
>
> Please search the archive of this mailing list; this exact question
> has been asked and answered many times before.
>
>
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



user_id in admin pages

2008-12-10 Thread Django Newbie

This is probably an easy one, but I've tried what make sense to me with 
not success.  What I want to do is in my admin pages, use the User 
module and enter the the user_id of whoever is logged in to add an entry 
in one of my foreign key tables.

How can set a field equal to the user_id to be entered into the db?

Example:
Models:
from django.db import models
from datetime import datetime
from django.contrib.auth.models import User

RATINGS = (
   ('1','1'),
   ('2','2'),
   ('3','3'),
   ('4','4'),
   ('5','5'),
)

class Recipes(models.Model):
  recipe_name = models.CharField(max_length=200)
  ingredients = models.TextField()
  instructions = models.TextField()
  image = 
models.ImageField(upload_to="/home/dave/dinnertools/image_upload",blank=True)
  entered_by = models.ForeignKey(User,blank=True)
  date_entered = models.DateTimeField(auto_now_add=True,blank=True)

  def __unicode__(self):
return self.recipe_name

class Rating(models.Model):
  recipe = models.ForeignKey(Recipes)
  rating = models.IntegerField(choices=RATINGS)
  user = models.ForeignKey(User)

class DishCategory(models.Model):
  category_name = models.CharField(max_length=255)

class RecipeCategory(models.Model):
  category_name = models.ForeignKey(DishCategory)
  recipe = models.ForeignKey(Recipes)

class MyRecipes(models.Model):
  recipe_id = models.ForeignKey(Recipes)
  user = models.ForeignKey(User)

*
admin.py:

from dinnertools.recipes.models import Recipes
from dinnertools.recipes.models import Rating
from django.contrib.auth.models import User
from django.contrib import admin

class RatingChoices(admin.StackedInline):
  model = Rating
  extra = 1

class RecipeAdmin(admin.ModelAdmin):
  fields = ['recipe_name','ingredients','instructions','image']
  inlines = [RatingChoices]
  list_display = ('recipe_name','entered_by','date_entered')
  date_hierarchy = 'date_entered'

admin.site.register(Recipes,RecipeAdmin)

What I want to do is in RecipeAdmin add something like:
  entered_by = User.user_id

So how can set a field equal to the user_id to be entered into the db?

Thanks.

David Godsey

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can javascript call a python script?

2008-12-04 Thread Django Newbie

With AJAX you can.  Javascript is interpreted by the browser, and you 
want to call a serverside script.  Or you could do it as a form 
submission, but I assume you want it to happen without refreshing the 
page, so AJAX is how you would do that.

Eric wrote:
> Hello, this might be a silly question, but I'm wondering if javascript
> can call a python script, and if so, how?
>
> To elaborate, I'm trying to customize the admin change_list page so
> that editing can be done directly from the change_list, instead of
> clicking into the admin change_form page. To do this, I have a
> javascript that pops up a prompt box when an element in the
> change_list table is clicked. I'd then like to call a python script to
> modify that element in the database (since I don't believe the DB can
> be modified directly in the javascript).
>
> If this is unnecessary or just plain wrong, or if someone has a better
> way of editing items directly from the change_list, please let me
> know! Thanks much for the 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: rendering DB text in template

2008-11-28 Thread Django Newbie

Thank you.

Alex Koshelev wrote:
> Look at this:
> http://docs.djangoproject.com/en/dev/topics/templates/#id2
>
>
> On Fri, Nov 28, 2008 at 21:43, Django Newbie <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>
> So I have some text fields in the db that have some embedded html
> in the
> text.  How do I get the template to render the text as html?
>
> The text fields are recipe.ingredients and recipe.instructions
>
> 
> 
>   Recipes 
>  
>.RecipeName{
>  font-size: large;
>  font-weight: bold;
>}
>.Recipe{
>   width: 700px;
>   margin-left: 20px;
>   display: none;
>}
>  
>  
>function toggle(id) {
>  var e = document.getElementById(id);
>  if (e) {
>e.style.display = e.style.display == 'block' ? 'none' :
> 'block';
>  }
>}
>  
> 
> 
> {% if recipe_list %}
>
>{% for recipe in recipe_list %}
>  
> {{
> recipe.recipe_name }}
>  
> 
>
>  {{ recipe.ingredients}}
>
>
>{{ recipe.instructions}}
>
> 
>{% endfor %}
>  
>
>
> {% else %}
>No recipes are available.
> {% endif %}
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



rendering DB text in template

2008-11-28 Thread Django Newbie

So I have some text fields in the db that have some embedded html in the 
text.  How do I get the template to render the text as html?

The text fields are recipe.ingredients and recipe.instructions



   Recipes 
  
.RecipeName{
  font-size: large;
  font-weight: bold;
}
.Recipe{
   width: 700px;
   margin-left: 20px;
   display: none;
}
  
  
function toggle(id) {
  var e = document.getElementById(id);
  if (e) {
e.style.display = e.style.display == 'block' ? 'none' : 'block';
  }
}
  


{% if recipe_list %}

{% for recipe in recipe_list %}
  
 {{ 
recipe.recipe_name }}
  
 

  {{ recipe.ingredients}}


{{ recipe.instructions}}

 
{% endfor %}
 


{% else %}
No recipes are available.
{% endif %}

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Apache Setup

2008-11-26 Thread Django Newbie

Graham Dumpleton wrote:
>
> On Nov 26, 3:32 pm, Django Newbie <[EMAIL PROTECTED]> wrote:
>   
>> Hi Everybody,
>>
>> Django newbie here.  I'm trying to get it to work under apache with
>> mod_python on a freebsd server but running into problems.  I searched
>> the archives and found similar things, but I tried all the suggestions
>> and still no luck.
>>
>> The error:
>>
>> MOD_PYTHON ERROR
>>
>> ProcessId:  11226
>> Interpreter:'dinnertools'
>>
>> ServerName: 'gidget.cws-web.com'
>> DocumentRoot:   '/home/dave/www/gidget.cws-web.com'
>>
>> URI:'/dinnertools/'
>> Location:   '/dinnertools/'
>> Directory:  None
>> Filename:   '/home/dave/www/gidget.cws-web.com/dinnertools'
>> PathInfo:   '/'
>>
>> Phase:  'PythonHandler'
>> Handler:'django.core.handlers.modpython'
>>
>> Traceback (most recent call last):
>>
>>  File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py",
>> line 1537, in HandlerDispatch
>>default=default_handler, arg=req, silent=hlist.silent)
>>
>>  File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py",
>> line 1229, in _process_target
>>result = _execute_target(config, req, object, arg)
>>
>>  File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py",
>> line 1128, in _execute_target
>>result = object(arg)
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/core/handlers/modpython.py",
>> line 228, in handler
>>return ModPythonHandler()(req)
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/core/handlers/modpython.py",
>> line 201, in __call__
>>response = self.get_response(request)
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py",
>> line 67, in get_response
>>response = middleware_method(request)
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/contrib/sessions/middleware. 
>> py",
>> line 9, in process_request
>>engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/contrib/sessions/backends/db 
>> .py",
>> line 2, in 
>>from django.contrib.sessions.models import Session
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/contrib/sessions/models.py",
>> line 4, in 
>>from django.db import models
>>
>>  File "/usr/local/lib/python2.5/site-packages/django/db/__init__.py",
>> line 16, in 
>>backend = __import__('%s%s.base' % (_import_path,
>> settings.DATABASE_ENGINE), {}, {}, [''])
>>
>>  File
>> "/usr/local/lib/python2.5/site-packages/django/db/backends/mysql/base.py",
>> line 13, in 
>>raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
>>
>> My apache setup:
>> PythonImport /home/dave/dinnertools/egg.py dinnertools
>>
>>
>>  SetHandler python-program
>>  PythonHandler django.core.handlers.modpython
>>  SetEnv DJANGO_SETTINGS_MODULE settings
>>  PythonInterpreter dinnertools
>>  PythonOption django.root /dinnertools
>>  PythonDebug On
>>  PythonPath "['/home/dave/dinnertools'] + sys.path"
>>
>>
>> ImproperlyConfigured: Error loading MySQLdb module: Shared object
>> "libmysqlclient_r.so.15" not found, required by "_mysql.so"
>>
>> The egg.py file:
>>
>> import os
>> os.environ['PYTHON_EGG_CACHE'] = '/www/htdocs/egg_cache'
>>
>> my project directory:
>> # ll
>> total 9
>> -rw-r--r--  1 dave  dave 0 Nov 21 11:00 __init__.py
>> -rw-r--r--  1 dave  dave   145 Nov 21 11:01 __init__.pyc
>> -rw-r--r--  1 dave  dave67 Nov 25 15:03 egg.py
>> -rw-r--r--  1 dave  dave   546 Nov 21 11:00 manage.py
>> drwxr-xr-x  2 dave  dave   512 Nov 21 11:23 recipes
>> -rw-r--r--  1 dave  dave  2862 Nov 25 21:14 settings.py
>> -rw-r--r--  1 dave  dave  1817 Nov 25 10:26 settings.pyc
>> -rw-r--r--  1 dave  dave   541 Nov 25 10:30 urls.py
>> #
>>
>> DB connections of course work outside of the apache/mod_python
>> environment.  Also I would expect some temporary file to be unpacked in
>> the /www/htdocs/egg_cache directory, but I don't see any.  The
>> permissions on the egg_cache directory are such that ap

Apache Setup

2008-11-25 Thread Django Newbie

Hi Everybody,

Django newbie here.  I'm trying to get it to work under apache with 
mod_python on a freebsd server but running into problems.  I searched 
the archives and found similar things, but I tried all the suggestions 
and still no luck.

The error:

MOD_PYTHON ERROR

ProcessId:  11226
Interpreter:'dinnertools'

ServerName: 'gidget.cws-web.com'
DocumentRoot:   '/home/dave/www/gidget.cws-web.com'

URI:'/dinnertools/'
Location:   '/dinnertools/'
Directory:  None
Filename:   '/home/dave/www/gidget.cws-web.com/dinnertools'
PathInfo:   '/'

Phase:  'PythonHandler'
Handler:'django.core.handlers.modpython'

Traceback (most recent call last):

 File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py", 
line 1537, in HandlerDispatch
   default=default_handler, arg=req, silent=hlist.silent)

 File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py", 
line 1229, in _process_target
   result = _execute_target(config, req, object, arg)

 File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py", 
line 1128, in _execute_target
   result = object(arg)

 File 
"/usr/local/lib/python2.5/site-packages/django/core/handlers/modpython.py", 
line 228, in handler
   return ModPythonHandler()(req)

 File 
"/usr/local/lib/python2.5/site-packages/django/core/handlers/modpython.py", 
line 201, in __call__
   response = self.get_response(request)

 File 
"/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py", 
line 67, in get_response
   response = middleware_method(request)

 File 
"/usr/local/lib/python2.5/site-packages/django/contrib/sessions/middleware.py", 
line 9, in process_request
   engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])

 File 
"/usr/local/lib/python2.5/site-packages/django/contrib/sessions/backends/db.py",
 
line 2, in 
   from django.contrib.sessions.models import Session

 File 
"/usr/local/lib/python2.5/site-packages/django/contrib/sessions/models.py", 
line 4, in 
   from django.db import models

 File "/usr/local/lib/python2.5/site-packages/django/db/__init__.py", 
line 16, in 
   backend = __import__('%s%s.base' % (_import_path, 
settings.DATABASE_ENGINE), {}, {}, [''])

 File 
"/usr/local/lib/python2.5/site-packages/django/db/backends/mysql/base.py", 
line 13, in 
   raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)


My apache setup:
PythonImport /home/dave/dinnertools/egg.py dinnertools

   
 SetHandler python-program
 PythonHandler django.core.handlers.modpython
 SetEnv DJANGO_SETTINGS_MODULE settings
 PythonInterpreter dinnertools
 PythonOption django.root /dinnertools
 PythonDebug On
 PythonPath "['/home/dave/dinnertools'] + sys.path"
   

ImproperlyConfigured: Error loading MySQLdb module: Shared object 
"libmysqlclient_r.so.15" not found, required by "_mysql.so"

The egg.py file:

import os
os.environ['PYTHON_EGG_CACHE'] = '/www/htdocs/egg_cache'

my project directory:
# ll
total 9
-rw-r--r--  1 dave  dave 0 Nov 21 11:00 __init__.py
-rw-r--r--  1 dave  dave   145 Nov 21 11:01 __init__.pyc
-rw-r--r--  1 dave  dave67 Nov 25 15:03 egg.py
-rw-r--r--  1 dave  dave   546 Nov 21 11:00 manage.py
drwxr-xr-x  2 dave  dave   512 Nov 21 11:23 recipes
-rw-r--r--  1 dave  dave  2862 Nov 25 21:14 settings.py
-rw-r--r--  1 dave  dave  1817 Nov 25 10:26 settings.pyc
-rw-r--r--  1 dave  dave   541 Nov 25 10:30 urls.py
#

DB connections of course work outside of the apache/mod_python 
environment.  Also I would expect some temporary file to be unpacked in 
the /www/htdocs/egg_cache directory, but I don't see any.  The 
permissions on the egg_cache directory are such that apache should be 
able to write to it.

Any ideas?  I assume I need the extra setup related to egg file since 
the MySQLdb module has some egg files related to it.  Please let me know 
what I'm missing.

Thanks,

Yours truly, django newbie.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---