Re: authenticate=None mistery: can't authenticate from the web but it works from the command line

2012-08-19 Thread Joseph Mutumi
Hello,

I believe its a simple typo!

authenticate(user=usuario, password=clave)

should be

authenticate(username=usuario, password=clave)

Regards

On Sun, Aug 19, 2012 at 3:35 PM, Jorge Garcia wrote:

> Hi there. Im doing my first login form for an existing Django application.
> The thing is that when I give the correct usr/pswd from the
> web,  django.contrib.auth.authenticate returns systematically None.
> However, when I try the same thing from the Django shell it works.  I'm
> working with a "john" user created from the Django admin application, using
> the "password chang" form. Here's the code, and the Django command line
> output.
>
> My application and me will be eternally thankful for your help.
>
> ++COMMAND LINE
> python manage.py shell
> >>> from django.contrib.auth import authenticate
> >>> user = authenticate(username='john', password='johnpassword')
> >>> print user
> john
>
> ++VIEWS.PY
> from django.contrib.auth.models import User
>
> def index(request):
> return render_to_response('unoporuno/index.html', None,
> context_instance=RequestContext(request))
>
> def login_cidesal(request):
> usuario = request.POST['usuario']
> clave = request.POST['clave']
> user = authenticate(user=usuario, password=clave)
> return HttpResponse("logging in user:" + usuario + " with password:" +
> clave + " and authenticate result=" + str(user))
>
> ++URLS.PY
> urlpatterns = patterns('unoporuno.views',
>url(r'^$','index'),
>url(r'login/', 'login_cidesal'),
>
> ++INDEX.HTML
> http://www.w3.org/1999/xhtml"; xml:lang="es">
> 
> 
> 
> 
> 
> 
> {% csrf_token %}
> 
>  border="0"/>
> UnoporunO
> Buscador de personas especializado en movilidad profesional
> 
> Usuario: 
> Clave : 
> 
> 
> 
> 
>
> ++WEB RESULT TYPING usuario=john clave=johnpassword
> logging in user:john with password:johnpassword and authenticate
> result=None
>
>  --
> 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/-/1UKsQlJ5OB8J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: How to use Django with Apache and mod_wsgi

2012-08-19 Thread Joseph Mutumi
Hello,

Could you post the VirtualHost configuration for Apache?
That would greatly help us help you.

Regards

On Mon, Aug 20, 2012 at 12:30 AM, Seyfullah Tıkıç  wrote:

> Hello,
>
> I read the article below.
> https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/
>
> But still http://localhost redirects to
> /var/www/localhost/htdocs/index.html.
> I want http://localhost/ redirescts to /home/seyfullah/django/mysite.
> How can I do this?
>
> --
> SEYFULLAH TIKIÇ
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Distinct Values in ModelChoiceField

2012-08-19 Thread Joseph Mutumi
Hello,

I have a model that has a foreign key field that I want to use in a form as
a select box.
That particular field at times appears multiple times in the database. How
do I make it
only have distinct values?

This is a snippet, drop down will have repeated values if same color is
entered:

class FavoriteColor(models.Model):
color = models.CharField(max_length=255)

def __unicode__(self):
return self.color

class FavoriteThings(models.Model):
name = models.CharField(max_length=10)
color = models.ForeignKey(FavoriteColor)

class FavoriteThingsForm(forms.ModelForm):
class Meta:
model = FavoriteThings

Thank you

-- 
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: How to use Django with Apache and mod_wsgi

2012-08-20 Thread Joseph Mutumi
You would be good to organize your configuration. Try creating a file under
/etc/apache2/vhosts.d/
Probably my_domain.com (substitute my_domain.com with your actual domain).

And move all the configuration to it:

ServerAdmin webmaster@my_domain.com
DocumentRoot /usr/local/django/mysite/media/
ServerName my_domain.com
ServerAlias www.my_domain.com

#WSGIDaemonProcess site-1 user=user-1 group=user-1 threads=25
#WSGIProcessGroup site-1

Alias /media/ /usr/local/django/mysite/media/


Order deny,allow
Allow from all


WSGIScriptAlias / /home/seyfullah/django/mysite/apache/django.wsgi


Order deny,allow
Allow from all




You can remove the comments after you are sure its working

Regards

On Mon, Aug 20, 2012 at 2:39 PM, Joris  wrote:

> The DocumentRoot directive is missing from the httpd.conf, indicating you
> did not send all the required data. This may be because your attachment is
> incomplete:
>
> There is an include statement in your httpd.conf: "Include
> /etc/apache2/conf.d/*.conf"
> All files from that conf.d folder are also processed. Please look in files
> located in  /etc/apache2/conf.d/ for anything useful. Especially files that
> contain a documentroot directive
>
> Also, it may help if you post the output of
> apachectl -S
> (note: some distros want apache2ctl instead of apachectl)
>
> jb
>
>
>
> On Monday, August 20, 2012 11:30:49 AM UTC+2, stikic wrote:
>
>> httpd.conf file is in the attachment.
>>
>> 2012/8/20, Joseph Mutumi :
>> > Hello,
>> >
>> > Could you post the VirtualHost configuration for Apache?
>> > That would greatly help us help you.
>> >
>> > Regards
>> >
>> > On Mon, Aug 20, 2012 at 12:30 AM, Seyfullah Tıkıç 
>> wrote:
>> >
>> >> Hello,
>> >>
>> >> I read the article below.
>> >> https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/
>> >>
>> >> But still http://localhost redirects to
>> >> /var/www/localhost/htdocs/index.html.
>> >> I want http://localhost/ redirescts to /home/seyfullah/django/mysite.
>> >> How can I do this?
>> >>
>> >> --
>> >> SEYFULLAH TIKIÇ
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to django...@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> django-users...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>> >
>>
>>
>> --
>> SEYFULLAH TIKIÇ
>>
>  --
> 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/-/KkXJTQwbtYwJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Distinct Values in ModelChoiceField

2012-08-23 Thread Joseph Mutumi
@Melvyn Thank you. It actually worked out as you said. It needed a redesign.

On Wed, Aug 22, 2012 at 1:44 PM, Sithembewena Lloyd Dube
wrote:

> @Melvyn, thanks - that makes sense.
>
>
> On Wed, Aug 22, 2012 at 3:18 AM, Melvyn Sopacua wrote:
>
>> On 22-8-2012 3:04, Sithembewena Lloyd Dube wrote:
>>
>> > I found your response to the OP interesting, yet I cannot quite follow
>> it.
>> > Even if he sets a unique attribute (presumably Boolean/ Checkbox?)
>>
>> Nope, this unique attribute:
>> 
>>
>> By design, the foreign key will now not contain duplicates so distinct
>> is no longer necessary.
>> --
>> Melvyn Sopacua
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: What happens when you use ``select_for_update`` with ``select_related``?

2012-08-23 Thread Joseph Mutumi
I'm not sure but you can look at the generated query and post it to the
relevant database mailing list?

Go in through: manage.py shell then follow instructions in FAQ
https://docs.djangoproject.com/en/dev/faq/models/#how-can-i-see-the-raw-sql-queries-django-is-running


On Mon, Aug 20, 2012 at 6:02 AM, Yo-Yo Ma  wrote:

> Given a model ``Employee`` with a foreign key ``company`` pointing to a
> model called ``Company``, would the following example lock both the
> ``Employee`` and ``Company`` rows that were selected?
>
> employee =
> Employee.objects.select_for_update().select_related('company').get(pk=1)
>
> Or, would only the ``Employee`` row be locked?
>
> --
> 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/-/Ps3gJ6JiSnMJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: ModelMultipleChoiceField with MultiWidget ?

2012-08-26 Thread Joseph Mutumi
Disclaimer - I have never done this before!

>From what I see I reckon you will need to create both a custom field and a
custom widget!

I think so because if you have TextInputs validation may fail on the
ModelMultipleChoiceField?
I would think you need to override the methods: __init__, clean, to_python
and compress.

I think you will also need to create a more customized widget inheriting
directly from MultiWidget?
I think you would need to override the methods: __init__, render, decompress

But I'm no expert ;-(


On Sun, Aug 26, 2012 at 7:42 PM, Nicolas Emiliani  wrote:

> Hi,
>
> I've been struggling with this for the past two weeks, and i think it's
> time to ask.
>
> I have and admin form that has a ModelMultipleChoiceField that is used to
> display
> a ManyToMany model field that specifies a through model
>
> class Person(models.Model):
> name = models.CharField(max_length=10)
> attributes = models.ManyToManyField('Attribute',through='Has',
> blank=True, null=True)
>
> class Has(models.Model):
> person = models.ForeignKey('Person')
> attribute = models.ForeignKey('Attribute')
> value = models.CharField(max_length=10)
>
>
> class Attribute(models.Model):
> name = models.CharField(max_length=10)
> atype = models.CharField(max_length=2,
>   choices=(('TF','true/false'),
>('IN','text')))
>
>
> class PersonAdminForm(forms.ModelForm):
>
> class Meta:
> model = Person
>
> attrs = forms.ModelMultipleChoiceField( \
> label='Attributes',
> queryset=Attribute.objects.all(),
> widget=forms.CheckboxSelectMultiple(),
> )
>
>
> This CheckboxSelectMultiple works fine, but I want to be able to render
> each relation according to the Attribute.atype value, meaning if it is TF,
> then tender it as a CheckBox, if it is IN the render it as an InputText
>
> I inherited from CheckboxSelectMultiple so it does that, but then when I'm
> on the admin form and for one specific attribute of type IN, rendered as a
> TextInput,  I set a value (let's say 500) and then press save , the method
>
> SelectMultiple.value_from_datadict gets called and passed as data :
>
>  [u'GWLnuoTSTjjLmpYOizodBA4VA1FmwdQw'],
> u'_continue': [u'Save and continue editing'], u'name': [u'nico'],
> u'attrs': [ u'2']}>
>
> And this is what has been driving me nuts!
>
> u'attrs': [ u'2'],
>
> As you can see it only passes the id of the attribute, not the id and the
> value. What I
> need is something like
>
> u'attrs': [ (u'2','500')],
>
> Any ideas on how to fix this ?
>
> Thanks!
>
> --
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Dependent Ajax Form Fields

2012-08-26 Thread Joseph Mutumi
Hello,

If A is a model with ForeignKey relationships to B. What would be the best
way of rendering two
selectboxes, A and B. The values of B are the values filtered through using
the relationship with
the selected value of A via an AJAX call.

I need to get these values from the DB as well as have Django validation
work out? All ideas are
welcome!

-- 
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: Dependent Ajax Form Fields

2012-08-27 Thread Joseph Mutumi
Thank you for the help!

On 8/27/12, Jani Tiainen  wrote:
> 26.8.2012 21:54, Joseph Mutumi kirjoitti:
>> Hello,
>>
>> If A is a model with ForeignKey relationships to B. What would be the
>> best way of rendering two
>> selectboxes, A and B. The values of B are the values filtered through
>> using the relationship with
>> the selected value of A via an AJAX call.
>>
>> I need to get these values from the DB as well as have Django validation
>> work out? All ideas are
>> welcome!
>
> Well it works exactly as you described. You hookup with your JS
> framework to change event of selectbox A to run query and update
> contents (by calling django view with correct params) of selectbox B.
>
> I suggest that you keep validation to happen on form submit rather than
> when updating two field values.
>
> Just find out what is the best way to do that with your JS framework.
>
> Try googling "dependent selectboxes  should get you going. By adding keyword Django might give even more help.
>
> --
> Jani Tiainen
>
> - Well planned is half done and a half done has been sufficient 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Problem serving files from media directory

2012-08-28 Thread Joseph Mutumi
Hi, Django isn't responsible for serving any kind of static files in
production.
It is not a web server ! You need to configure the web server you are using
to serve the files in that folder.

The documentation has a good example conf for Apache:
https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/#serving-files

On Tue, Aug 28, 2012 at 1:40 AM, neridaj  wrote:

> Hello,
>
> I've deployed a new website to my staging and production servers but for
> some reason the images in the media directory are displaying 404 errors.
> The path to the image is correct and the image is located at that path:
>
>  width="570" height="270" style="">
>
> ls -la ~/.virtualenvs/website/project/media/projects/hair/2012/test-1
> total 144
> drwxr-x--- 2 username username   4096 Aug 27 16:43 .
> drwxr-x--- 3 username username   4096 Aug 27 16:43 ..
> -rwxrwxr-x 1 username username 131719 Aug 27 16:43 13221803.jpg
>
> settings.py:
>
> MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
> MEDIA_URL = '/media/'
>
> Am I having problems because the image file is nested within other
> directories? Files are being served from the static directory just fine,
> any ideas?
>
> Thanks,
>
> Jason
>
> --
> 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/-/Kk3KOw-L4RQJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: form doesn't validate when trying to upload file

2012-09-09 Thread Joseph Mutumi
I'm assuming you are using the forms.ModelForm for your model? Say
LicenceForm?

class LicenseForm(forms.ModelForm):
class Meta:
model = License

According to the doc you have to pass all relevant QueryDicts to the form
__init__
when you are creating a bound instance. In a nutshell make sure your doing:

# The view function
def handle_upload(request):
# Get request logic ...
if request.method == "POST":
form = LicenceForm(request.POST, request.FILES)
if form.is_valid():
   #save input data
   form.save()
   #continue with other stuff

More on the docs:
https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files-with-a-model


On Sun, Sep 9, 2012 at 5:56 PM, mapapage  wrote:

> Hi! It's my first time trying to achieve the ''file upload functionality'
> and I need your help. I'm working on a legacy db and I'm supposed to do the
> file upload in a table that gets created this way:
>
> CREATE TABLE  "LICENCE"
>(  "ID" NUMBER NOT NULL ENABLE,
>   "VEH_ID" NUMBER NOT NULL ENABLE,
>   "DTP_ID" NUMBER NOT NULL ENABLE,
>   "LICENCENO" VARCHAR2(50 CHAR) NOT NULL ENABLE,
>   "ISSUEDATE" DATE,
>   "STARTDATE" DATE,
>   "EXPIREDATE" DATE,
>   "DOCPATH" VARCHAR2(500 CHAR),
>   "CHECKFLAG" NUMBER(1,0) NOT NULL ENABLE,
>CONSTRAINT "LIC_PK" PRIMARY KEY ("ID") ENABLE,
>CONSTRAINT "LIC_DTP_FK" FOREIGN KEY ("DTP_ID")
> REFERENCES  "DOCTYPES" ("ID") ENABLE,
>CONSTRAINT "LIC_VEH_FK" FOREIGN KEY ("VEH_ID")
> REFERENCES  "VEHICLES" ("ID") ENABLE
>)
> /
>
> With inspectdb, I got this table:
>
> class Licence(models.Model):
>
> id = models.DecimalField(unique=True, primary_key=True, max_digits=127, 
> decimal_places=0)
> veh_id = models.ForeignKey(Vehicles, db_column='veh_id')
> dtp_id = models.ForeignKey(Doctypes, db_column='dtp_id')
> licenceno = models.CharField(max_length=200)
> issuedate = models.DateField(null=True, blank=True)
> startdate = models.DateField(null=True, blank=True)
> expiredate = models.DateField(max_length=2000, blank=True)
> docpath = models.CharField(max_length=200)
> checkflag = models.IntegerField()
>
> def __unicode__(self):
> return self.licenceno
>
>
> How should I handle the upload?My thought after reading the file upload 
> documentation was to modify the docpath to filefield. Is that the right 
> practice?Because I tried it, and the form doesn't validate, I get the error 
> "No file chosen". Can anyone guide me through this?Thank you..
>
>  --
> 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/-/eo_e4m3hye8J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Submitting data from a form

2012-09-14 Thread Joseph Mutumi
Hi,

Let me give you a code sample that would be hopefully a push in the right
direction.
Simply follow these steps:

   1. Create your model. Its the code interface to your data source
   (database)
   2. Create your form. Forms are used for processing input data
   (validation, error reporting etc)
   3. Create your view. You should at least be able to link up a url
   pattern to a view. If you can't please go through the tutorial
   4. Create your template. This is the html returned to the client.

Note: Samples for your consideration:

#--- in models.py
from django.db import models
from django import forms

CHOICES = (('big', 'big'),('medium', 'medium'), ('small', 'small'))

class SimpleColumn(models.Model):
my_column = models.CharField(max_length=255, choices=CHOICES)

class SimpleColumnForm(forms.ModelForm):
class Meta:
model = SimpleColumn

#-- in views.py
from django.shortcuts import render
from models import SimpleColumnForm

def view_column(request):
if request.method == "POST":
form = SimpleColumnForm(request.POST)
if form.is_valid():
form.save()
else:
form = SimpleColumnForm()
return render(request, 'view_column.html', {'form': form})



{% csrf_token %}
{{ form }}
Save


Please go through the tutorial!
https://docs.djangoproject.com/en/1.4//intro/tutorial01/
It is very well written and after 1 hour or so you will have gotten the
concepts.

Enjoy Django!


On Thu, Sep 13, 2012 at 2:58 PM, Tom Evans  wrote:

> On Thu, Sep 13, 2012 at 6:26 AM, KVR  wrote:
> > Hi,
> > I am a Django learner .
> > I need to do a requirement as described below.
> >
> > 1.There is a column in a model
> > 2.I want to create a template with a select button in that.
> > 3.On selecting an option and submitting, the column should be updated
> with
> > the submitted value.
> >
> > Please give me some idea on how to do this?
> >
>
> The Django tutorial is a 4 part tutorial guiding you through creating
> a model, creating a view that uses that model, and creating forms to
> create or edit a model. It is specifically designed to take someone
> who has never used django to a point where they can create models,
> views and forms to process those models.
>
> I suggest you attempt to complete the tutorial, and come ask questions
> on here iff you get stuck.
>
> https://docs.djangoproject.com/en/1.4//intro/tutorial01/
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: has_perm returns wrong value

2012-11-14 Thread Joseph Mutumi
I believe default permissions created are: add_*, change_* and delete_*.
And the format for a permission would be something like: *app_name*.add_*
model_name*

So what happens when you try:

user.has_perm('structures.add_post')
user.has_perm('structures.change_post')

If you are registering your own permissions it should be done like the docs
say:
https://docs.djangoproject.com/en/dev/topics/auth/#custom-permissions


On Wed, Nov 14, 2012 at 10:40 AM, Brehnen Wong  wrote:

> When I do user.has_perm(), I get FALSE, but I have added permissions to
> user manually with user.user_permissions.add(51) on the django
> console/shell, and I even show all the permissions
> with user.user_permissions.all().  (Also, if i
> use user.has_perm('sdlfjksdf'), it returns FALSE rather than an error
> saying that that permission does not exist, but that is another "issue").
>  user is active
>
> DJANGO SHELL/CONSOLE
> >>> user.has_perm('structures.edit_post')
> False
> >>> user.has_perm('structures.create_post')
> False
> >>> user.user_permissions.all()
> [,  permission | Can add permission>,  change permission>,  permission>, ,
> ]
>
> MYSQL: auth_permission
> ...
> | 50 | Can delete post  |  13 |
> delete_post|
> | 51 | Can create new post  |  13 |
> create_post|
> | 52 | Can edit all users' posts|  13 |
> edit_post  |
>
> ++--+-++
>
> MYSQL: django_content_type
> ++--+--+--+
> | id | name | app_label| model|
> ++--+--+--+
> |  1 | permission   | auth | permission   |
> |  2 | group| auth | group|
> |  3 | user | auth | user |
> |  4 | content type | contenttypes | contenttype  |
> |  5 | session  | sessions | session  |
> |  6 | site | sites| site |
> |  9 | category | structures   | category |
> | 10 | thread   | structures   | thread   |
> | 11 | bookmark | structures   | bookmark |
> | 12 | subscription | structures   | subscription |
> | 13 | post | structures   | post |
> ++--+--+--+
>
>
>
>  --
> 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/-/BEYgkvLkouEJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Escape percent sign in QuerySet.extra()

2012-12-02 Thread Joseph Mutumi
I think to escape a % use %%

On Sun, Dec 2, 2012 at 1:16 PM, Martin Svoboda wrote:

> Hi,
> I want use postgresql pg_trgm module in django. pg_trgm defines special
> operator percent sign. How should I escape it in django query extra method?
>
> # Pure SQL
> SELECT content, similarity(content, 'text') AS sml
>   FROM table
>   WHERE content % 'text'
>   ORDER BY sml DESC, content;
>
> # Extra throws IndexError 'tuple index out of range'
> # I tried escape % with %%, or \%, but it throws same exception
> objects = MyModel.objects.extra(
> select={'rank': 'similarity(content, %s)'},
> select_params=[content],
> where='content % %s',
> params=[content],
> order_by=['-rank']
> )
>
> # Raw query works fine
> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS rank
> FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''', [content,
> content])
>
> How should I escape persent sign in extra() method?
>
> Thank you!
>
> --
> 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/-/2euBM5lHjZEJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Escape percent sign in QuerySet.extra()

2012-12-02 Thread Joseph Mutumi
Sorry I hadn't seen your comment, have you tried %%% ?

On Mon, Dec 3, 2012 at 7:28 AM, Joseph Mutumi  wrote:

> I think to escape a % use %%
>
>
> On Sun, Dec 2, 2012 at 1:16 PM, Martin Svoboda 
> wrote:
>
>> Hi,
>> I want use postgresql pg_trgm module in django. pg_trgm defines special
>> operator percent sign. How should I escape it in django query extra method?
>>
>> # Pure SQL
>> SELECT content, similarity(content, 'text') AS sml
>>   FROM table
>>   WHERE content % 'text'
>>   ORDER BY sml DESC, content;
>>
>> # Extra throws IndexError 'tuple index out of range'
>> # I tried escape % with %%, or \%, but it throws same exception
>> objects = MyModel.objects.extra(
>> select={'rank': 'similarity(content, %s)'},
>> select_params=[content],
>> where='content % %s',
>> params=[content],
>> order_by=['-rank']
>> )
>>
>> # Raw query works fine
>> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS
>> rank FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''',
>> [content, content])
>>
>> How should I escape persent sign in extra() method?
>>
>> Thank you!
>>
>> --
>> 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/-/2euBM5lHjZEJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

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



Re: HTML Source on Browser Rendering

2013-01-06 Thread Joseph Mutumi
Hello,

I think you should also check the 'Content-Type' being received client-side
in the HTTP headers. You can use something curl or Firebug.

On Sun, Jan 6, 2013 at 1:40 PM, Ryoichiro Kamiya  wrote:

> Hi,
>
> I'm testing Django template rendering in development environment, but one
> of the page shows HTML source (after all Django tag executed) instead of
> HTML.
>
> 1. Content Type
> The first thing I check is the Content Type but it's correctly set up (and
> it's in header template and shared with other pages that show contents
> correctly.
>
> 
>
>
> When I copied & pasted to another template and it works.
>
>
> 2. Browser
>
> I checked it in another browser (i.e. Chrome) but it returned the same result.
>
>
> 3. Reboot runserver
>
> also it didn't change the output.
>
>
> Is there anything else I should check?
>
> Thanks in advance.
>
>
> Regards,
>
> Ryo
>
>  --
> 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/-/FyjKgMAxm0YJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: looking for an apache/system admin master

2013-06-18 Thread Joseph Mutumi
If they are requesting urls that do not exist why are you worried? Just
block that IP address in the
vhost configuration and continuously monitor the server for strange or
unexpected traffic.

You can look into something like munin or graphite.


On Tue, Jun 18, 2013 at 8:26 PM, MattDale  wrote:

> I've been using windows/django1.4/apache2.2 for a couple intranet apps and
> it has been working well.  I recently had our admin open up a port in our
> firewall to deploy another app publicly. We weren't using the app and there
> were issues when testing, since both the admin and myself are newbies to
> deploying publicly with Apache with SSL. So we left the server as is and
> tested UX for this app on an external host.  We installed a new system wide
> firewall last week which the admin thought would help with our issues so I
> went to do some server prep today to bring the app on an internal server
> again.
>
> A check of the access logs found a specific external IP address hitting
> the server every 1/4 second with strange URLs that look to be commonly used
> php urls since June 7,2013.  It has been getting hit for DAYs and I just
> wasn't monitoring the server. Each of the requests either 302'd or 404'd
> and there are thousands of them.  I stopped the server, and sent an email
> to the admin to close that port down.
>
> Since neither I nor the system admin know much about deploying, is there
> anywhere I can look to hire someone to help get this app deployed safely?
> Our policies require SSL and we are willing to use other OS or servers, we
> just need someone who knows what they are doing.
>
> We are in the NYC vicinity.
>
> Thanks,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Mysterious error messages

2013-09-23 Thread Joseph Mutumi
Don't use Satchmo but looks like `shop_config` is not defined when you
context_processors are called?

This is because from it looks like it gets the shop_config based on the
current site based on the host. If the domain name saved in the admin for
the site corresponding to the SITE_ID in your settings.py is incorrect or
different from the host header in the HTTP request, it could possible cause
this error.


On Sun, Sep 22, 2013 at 6:02 PM, kooliah <
kool...@djeve.sites.djangohosting.ch> wrote:

>  I'm sorry but i started to send this message at 12.09 ...and at 14.00
> google groups still does not show me neither on mail or web-interface. so i
> resend...
>
> Sorry again, next time i'll wait 24 hours, to see if a post is sent...
>
>
>
>
>
> On 09/22/2013 04:27 PM, Avraham Serour wrote:
>
> really? how many times do you need to send and resend and cross post?
>
>
> On Sun, Sep 22, 2013 at 1:23 PM,  wrote:
>
>>  Everyday i receive 5-10 mysterious error messages of this kind
>>
>> ... ERRORS.
>>
>>   File
>> "../satchmo/satchmo/apps/satchmo_store/shop/context_processors.py",
>> line 31, in settings
>> 'shop_name': shop_config.store_name,
>>
>> AttributeError: 'NoneType' object has no attribute 'store_name'
>>
>>
>> > path:/plugins/tinymce_plugin/tiny_mce/plugins/more/editor_plugin.js,
>> GET:,
>> POST:,
>>
>> 
>>
>>   File
>> ".../satchmo/satchmo/apps/satchmo_store/shop/context_processors.py", line
>> 31, in settings
>> 'shop_name': shop_config.store_name,
>>
>> AttributeError: 'NoneType' object has no attribute 'store_name'
>>
>>
>> > path:/admin/login.aspx,
>> GET:,
>>
>> 
>>
>>   File "/django/db/backends/postgresql_psycopg2/base.py", line 52, in
>> execute
>> return self.cursor.execute(query, args)
>>
>> DatabaseError: server closed the connection unexpectedly
>> This probably means the server terminated abnormally
>> before or while processing the request.
>>
>>
>>
>> > path:/art_folder/text-image_Series-1.jpg,
>> GET:,
>> POST:,
>>
>> 
>>
>> 
>>
>> 
>>
>> ...END ERRORS..
>>
>> All of them do not depend by my code but by django/satchmo source code,
>> and never rise on developing serverbut the thing I don't understand is
>> paths I have no paths like them...Why it does not give "page not found"
>> but Errors ??
>> If i give that url in browser it correctly gives me "page not
>> found"
>>
>> Thank you
>>
>> Alkatron
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Problem when getting the ID of the record just created

2014-10-13 Thread Joseph Mutumi
Should get the flow instance from the form.save() so:

user = User.objects.get(pk=self.request.user.id)
flow = form.save()
log = Log(user=user, flow=flow, state=1)

On Mon, Oct 13, 2014 at 4:13 PM, Daniel Grace  wrote:

> Hi,
> I have problem when getting the ID of the record just created.
>
> class CreateFlow(CreateView):
> model = Flow
> fields = ['state']
> template_name = 'create_flow.html'
> def form_valid(self, form):
> user = User.objects.get(pk=self.request.user.id)
> flow = Flow.objects.get(pk=self.kwargs['pk'])
> log = Log(user=user, flow=flow, state=1)
> log.save()
> return super(CreateFlow, self).form_valid(form)
>
> ... gives the error:
> Request Method: POST
> Request URL: http://127.0.0.1:8000/create/
> Django Version: 1.7
> Exception Type: KeyError
> Exception Value:
> 'pk'
> Exception Location: C:\landy\cresta\flow\views.py in form_valid, line 64
> Python Executable: C:\landy\Scripts\python.exe
> Python Version: 3.4.0
> Python Path:
> ['C:\\landy\\cresta',
>  'C:\\Windows\\system32\\python34.zip',
>  'C:\\Python34\\DLLs',
>  'C:\\Python34\\lib',
>  'C:\\Python34',
>  'C:\\landy',
>  'C:\\landy\\lib\\site-packages']
> Server time: Mon, 13 Oct 2014 13:40:49 +0100
>
> What is the correct way to get the ID of the record just created?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8aaceba9-0203-489a-a57f-09fa26ce163c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp__uazs18i6ms6Hmks%3DaecRR1B%3DcoH-h9yweVt%3D1ABADQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Email Templates and the full website URL

2013-11-29 Thread Joseph Mutumi
That could work but isn't it a bit insecure? I think it will be susceptible
to a header injection(http://en.wikipedia.org/wiki/HTTP_header_injection).
I would rather create a setting with the domain name in settings.py and
then call it from the template or write a custom template tag.


On Fri, Nov 29, 2013 at 2:55 PM, Rafael E. Ferrero  wrote:

> Good work!!
>
>
>
> 2013/11/29 Vibhu Rishi 
>
>> Thanks for the links. I had done the google searches and gone through
>> them, but they seemed to me a lot of work to get something simple.
>>
>> I finally did the following. Any comments welcome if this is not a good
>> way to do.
>>
>> In my view, I pass a context object of the request to the email template.
>> I need the request as i also want to put in the user's name.
>>
>> in the email template now I changed it to :
>> http://{{request.get_get_host}}{% url "project.views.details"
>> project.id %}">{{ project }}
>>
>> This seems to be working and quite simple too !
>>
>> Regards,
>> Vibhu
>>
>>
>>
>>
>> On Fri, Nov 29, 2013 at 4:26 PM, Rafael E. Ferrero <
>> rafael.ferr...@gmail.com> wrote:
>>
>>>
>>> https://docs.djangoproject.com/en/dev/ref/contrib/sites/#getting-the-current-domain-for-full-urls
>>>
>>>
>>> 2013/11/29 Vibhu Rishi 
>>>
  hi,

 I have a setup where I have a project details page, and I can do a
 "send email" which should send the email with the URL.

 Email is working fine.

 The problem is that i am getting a relative url in the tempalte

 I have the following in the html email template :
 {{ project
 }}

 This give me a URL in the email as /projects/1 ( 1 being the project id)

 How do i prepend the url of the server here ? e.g. I want this to be
 http://localhost:8000/projects/1

 Vibhu

 --
 Simplicity is the ultimate sophistication. - Leonardo da Vinci
 Life is really simple, but we insist on making it complicated. -
 Confucius

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAPiONwn6cHwi51fJ63oFUOLof2QmFqsSeqz2VeOM_Jxk%2BaUYGQ%40mail.gmail.com
 .
 For more options, visit https://groups.google.com/groups/opt_out.

>>>
>>>
>>>
>>> --
>>> Rafael E. Ferrero
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAJJc_8WWUyfwYd1cjxNzvm0xe5LjUTNDjPGDnYaaxE9w3B1C-g%40mail.gmail.com
>>> .
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> --
>> Simplicity is the ultimate sophistication. - Leonardo da Vinci
>> Life is really simple, but we insist on making it complicated. -
>> Confucius
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPiONw%3D7Uh9uReNyCCzhGb%3D09WHCzY9rSPp9mYn_eJRsHwmNpw%40mail.gmail.com
>> .
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> --
> Rafael E. Ferrero
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJJc_8WiwQjgNPKX4RZ0eQu%3DkYz%2BH51BywB0rQMVJ4u8XW8hbw%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send em

Re: Filtering by month doesn't work

2013-11-29 Thread Joseph Mutumi
I think the model is not being saved because no instance is being
constructed by the form. Either make call to event_form.is_valid() of
event_form.full_clean(), the former being preferred.


On Tue, Nov 26, 2013 at 8:30 PM, Leonardo Giordani <
giordani.leona...@gmail.com> wrote:

> Are you sure that filtering using a string is the same as filtering using
> an int? I think that Django doesn't automatically convert it. So the
> condition
>
>
> events = Event.objects.filter(end__month='11')
>
> should be
>
> events = Event.objects.filter(end__month=11)
>
> Indeed 
> documentationdoes
>  things this way. I see that you succeded in filtering with
>
> filter(end_start='2013')
>
> perhaps end__startswith? In that case you are treating it as a string.
> May you please check this and let me know?
>
> Cheers,
>
> Leo
>
>
>
> Leonardo Giordani
> Author of The Digital Cat 
> My profile on About.me  - My GitHub
> page  - My Coderwall 
> profile
>
>
> 2013/11/26 Vojtěch Tranta 
>
>> from django.db import models
>> from django.contrib.auth.models import User
>> from student import Student
>> from eventtype import EventType
>> from django import forms
>> import datetime
>>
>> class Event(models.Model):
>> user = models.ForeignKey(User)
>> student = models.ForeignKey(Student)
>>  place = models.CharField(max_length=200, null=True)
>> type = models.ForeignKey(EventType)
>> start = models.DateTimeField('event start', default=datetime.datetime.now)
>>  end = models.DateTimeField('event end', default=datetime.datetime.now)
>> absence = models.NullBooleanField()
>>  note = models.TextField(null=True)
>> created = models.DateTimeField('created time')
>> created_by = models.ForeignKey(User, related_name='event creator')
>>  description = models.TextField(null=True)
>>
>> class Meta:
>> app_label = 'jvc'
>>
>> def __unicode__(self):
>> return self.type.name +' '+ self.student.fullname +'
>> '+self.start.strftime('%d.%m.%Y')
>>
>> I should mention that I have my models in separated files in "models"
>> folder inside app called "jvc"
>>
>> Dne úterý, 26. listopadu 2013 8:25:40 UTC+1 Leo napsal(a):
>>>
>>> May you please post your Event model?
>>>
>>> Leonardo Giordani
>>> Author of The Digital 
>>> Cat
>>> My profile on 
>>> About.me-
>>>  My GitHub
>>> page-
>>>  My Coderwall
>>> profile
>>>
>>>
>>> 2013/11/26 Начаров Михаил 
>>>
  Hi Tranta.
 In my projects this functionality works fine.
 What version of django did you used?
 Do you sure that field end in Event table contains November dates?

 Also, you can use *today.month* instead of  *int(today.strftime('%m')*)
 and* today.year *instead of  *int(today.strftime('%Y')).*
 And in django docs says that it necessary to validate your form before
 use it:

 *if event_form.is_valid():*
 *event = event_form.save()*


 вторник, 26 ноября 2013 г., 5:24:21 UTC+6 пользователь Vojtěch Tranta
 написал:

> Hi,
> do you have any clue why this does not work?
>
> def index(request):
> if request.method == 'POST' and request.POST:
>  event_form = EventForm(request.POST)
> event = event_form.save()
>
> today = datetime.date.today();
>  year = int(today.strftime('%Y'))
> month = int(today.strftime('%m'))
> events = Event.objects.filter(end__month='11')
>  # events = Event.objects.all()
> pdb.set_trace()
> cal = jvccalendar.HTMLCalendar(jvccalendar.MONDAY).formatmonth(year,
> month, events)
>  form = EventForm()
> return render_to_response('jvc/index.html', {'cal': cal, 'side_form':
> form}, context_instance=RequestContext(request))
>
>
> I am still getting "events" as empty, filtering using
> filter(end_start='2013') works, but filtering by month does not, I googled
> as much as I could, but no luck. I copied code from StackOverflow, but no
> luck
> Thank you!
>
  --
 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...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.

 Visit this group at http://groups.google.com/group/django-users.
 To view this disc

Re: Email Templates and the full website URL

2013-12-03 Thread Joseph Mutumi
Its not that easy to do but instead of generating the link say:
http://myrealsite.com/admin/change_password

If HTTP_HOST is somehow messed up say by Man In the Browser, in the
email, you could get something like:

http://hackersite.com/admin/change_password

If the user isn't paying attention, they can end up giving credentials
to third party!
Its just a corner case, but hackers look for corner cases!

On 12/2/13, Vibhu Rishi  wrote:
> Not sure how the header injection will work in this case ?
>
> As I see it, I am using this in the email text for the email body. This is
> generated and sent in a view function I have. So, how will the http header
> get inserted in this flow ?
>
> Vibhu
>
>
>
> On Fri, Nov 29, 2013 at 7:39 PM, Joseph Mutumi  wrote:
>
>> That could work but isn't it a bit insecure? I think it will be
>> susceptible to a header injection(
>> http://en.wikipedia.org/wiki/HTTP_header_injection). I would rather
>> create a setting with the domain name in settings.py and then call it
>> from
>> the template or write a custom template tag.
>>
>>
>> On Fri, Nov 29, 2013 at 2:55 PM, Rafael E. Ferrero <
>> rafael.ferr...@gmail.com> wrote:
>>
>>> Good work!!
>>>
>>>
>>>
>>> 2013/11/29 Vibhu Rishi 
>>>
>>>> Thanks for the links. I had done the google searches and gone through
>>>> them, but they seemed to me a lot of work to get something simple.
>>>>
>>>> I finally did the following. Any comments welcome if this is not a good
>>>> way to do.
>>>>
>>>> In my view, I pass a context object of the request to the email
>>>> template. I need the request as i also want to put in the user's name.
>>>>
>>>> in the email template now I changed it to :
>>>> http://{{request.get_get_host}}{% url "project.views.details"
>>>> project.id %}">{{ project }}
>>>>
>>>> This seems to be working and quite simple too !
>>>>
>>>> Regards,
>>>> Vibhu
>>>>
>>>>
>>>>
>>>>
>>>> On Fri, Nov 29, 2013 at 4:26 PM, Rafael E. Ferrero <
>>>> rafael.ferr...@gmail.com> wrote:
>>>>
>>>>>
>>>>> https://docs.djangoproject.com/en/dev/ref/contrib/sites/#getting-the-current-domain-for-full-urls
>>>>>
>>>>>
>>>>> 2013/11/29 Vibhu Rishi 
>>>>>
>>>>>>  hi,
>>>>>>
>>>>>> I have a setup where I have a project details page, and I can do a
>>>>>> "send email" which should send the email with the URL.
>>>>>>
>>>>>> Email is working fine.
>>>>>>
>>>>>> The problem is that i am getting a relative url in the tempalte
>>>>>>
>>>>>> I have the following in the html email template :
>>>>>> {{ project
>>>>>> }}
>>>>>>
>>>>>> This give me a URL in the email as /projects/1 ( 1 being the project
>>>>>> id)
>>>>>>
>>>>>> How do i prepend the url of the server here ? e.g. I want this to be
>>>>>> http://localhost:8000/projects/1
>>>>>>
>>>>>> Vibhu
>>>>>>
>>>>>> --
>>>>>> Simplicity is the ultimate sophistication. - Leonardo da Vinci
>>>>>> Life is really simple, but we insist on making it complicated. -
>>>>>> Confucius
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Django users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send
>>>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>>>> To post to this group, send email to django-users@googlegroups.com.
>>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/django-users/CAPiONwn6cHwi51fJ63oFUOLof2QmFqsSeqz2VeOM_Jxk%2BaUYGQ%40mail.gmail.com
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
&

Re: How to get database data into a template sidebar

2013-12-03 Thread Joseph Mutumi
Some of the options you have are:
1) CBVs
2) custom template tags:
https://docs.djangoproject.com/en/1.5/howto/custom-template-tags/
3) template preprocessors:
https://docs.djangoproject.com/en/1.5/ref/settings/#template-context-processors

On 12/2/13, Drew Ferguson  wrote:
> Hi
>
> I am not really sure how to ask the Django docs what I want to do for this
> Could someone point me at the docs please
>
> I have a 3 column layout: left & right unchanging columns and a main column
> in the middle
>
> Left column is a fixed navigation template
> Centre column is the usual dynamic CBV templates
> Rite column is also currently a fixed template
>
> Now I want to show summary data collected from one of the data models in
> the rite pane - this rite column will always show the same thing
> regardless of which CBV is in the centre column. So I need some python
> called for the rite column but independent of view classes
>
> Do I have to add a function call to all CBV contexts to tabulate the data
> I want to list or is there a better way?
>
> Thanks
>
> --
> Drew Ferguson
> AFC Commercial
> http://www.afccommercial.co.uk
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp_B3T7iKFes%3DB1ejYfF9TvOahJmvHsPrVW_sFfQ4drCmg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Ajax post problem

2014-04-17 Thread Joseph Mutumi
You could try using $("form").serialize() to get the form inputs in
the ajax data. But from the URL it looks like your HTML is somehow
rendering badly. The form action is coming out as '/newmarkets/search/
method='

Kind regards

On 4/17/14, willyhakim  wrote:
> Hi everyone?
>
> I am trying to use ajax to do the following
>
> 1)User inputs a number.
> 2) I use ajax to return a query list into the same page.
>
> Here is my code
> and I keep getting this error
>
> Page not found (404)  Request Method: GET  Request URL:
> http://127.0.0.1:8000/newmarkets/search/%20method=?csrfmiddlewaretoken=VkKvStx1qGZOM1YxzM8xenGDbYRBnMPA
>
>
> Using the URLconf defined in exportAbroad.urls, Django tried these URL
> patterns, in this order:
>
>1. ^$ [name='index']
>2. ^about/$ [name='about']
>3. ^pricing/$ [name='pricing']
>4. ^market_research_tool/$ [name='market_research_tool']
>5. ^newmarkets/ ^$ [name='index']
>6. ^newmarkets/ ^search/$ [name='search']
>7. ^admin/
>8. ^accounts/
>9. ^static/(?P.*)$
>
> The current URL, newmarkets/search/ method=, didn't match any of these.
>
> *views.py*
> def index(request):
> context = RequestContext(request)
> return render_to_response('newmarkets/index.html', context)
>
> def search(request):
> if request.is_ajax() and request.method=='POST':
> UserHSnumber = request.POST['UserHSnumber']
> country_list = Imports.objects.filter(hs_number= UserHSnumber)[1:11]
> hsdescript = Products.objects.get(hs_number=UserHSnumber)
> data = {'markets': country_list, 'hsdescript': hsdescript}
> mimetype='application/json'
> else:
> raise Http404
> return HttpResponse(json.dumps(data), mimetype)
>
>
> *HTML*
>
> {%block body_block%}
> 
>  
>   What is your product's H.S number?
>
> 
>  {% csrf_token %}
>   
>   Submit
> 
> 
> 
> 
> 
> 
>
>
> *ajax.js*
>
>
>
>
>
> *$(document).ready(function() { $('#hs').click(function(){ $.ajax({
> type:"POST", url:"/newmarkets/search/",
> data:{"userHSnumber":$("#search").val()}, dataType: "json",
> success:function(data){ alert(data.message); } }); });// CSRF code
> function getCookie(name) {var cookieValue = null;var i =
> 0;if (document.cookie && document.cookie !== '') {var
> cookies = document.cookie.split(';');for (i; i <
> cookies.length; i++) {var cookie =
> jQuery.trim(cookies[i]);// Does this cookie string begin
> with the name we want?if (cookie.substring(0, name.length +
>
> 1) === (name + '=')) {cookieValue =
> decodeURIComponent(cookie.substring(name.length + 1));
> break;}}}return cookieValue;
>
> }var csrftoken = getCookie('csrftoken');function
> csrfSafeMethod(method) {// these HTTP methods do not require CSRF
> protectionreturn (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));}
>
>   $.ajaxSetup({crossDomain: false, // obviates need for sameOrigin
> testbeforeSend: function(xhr, settings) {if
> (!csrfSafeMethod(settings.type)) {
> xhr.setRequestHeader("X-CSRFToken", csrftoken);}}
> }); });*
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2132e3e5-9795-416d-9306-0b09a1698c6b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp_ENtkVOapK6QjaGPhGUUfbAC8CWxnOg%2BpQFbgZOuMRmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Order_by on queryset from chained filters not working

2014-04-24 Thread Joseph Mutumi
Just wondering why not cases = cases.order_by('case_number') ?

On 4/24/14, Shawn H  wrote:
> I've a search page that allows users to search for a "ZoningCase" by many
> different parameters, some from the ZoningCase object and some from several
>
> related objects.  The user can combine 1 or more of these parameters for
> their search.  My view chains together filters on the queryset based on the
>
> parameters selected.  All of this works fine. After I've finished chaining
> filters, I add one additional order_by chain, to sort the cases by
> case_number.  This works, in that the select query django builds is
> correct, having the correct order by clause at the end.
>
> Next, to prepare the cases for display, I iterate through the queryset and
> create a custom class for each case, appending that class to a list.  Here,
>
> it seems, the ordering breaks down.  It's as if the iterator ignores the
> order_by clause and just loops through however it feels like! As I begin
> the loop, it calls into query.py, the __iter__ method, and looking at
> self._result_cache, my ZoningCase objects in the queryset are unordered
> (e.g., 109, 129, 101,...).  I can easily fix it by sorting my final list,
> but since order_by has always worked for me when doing simply queries, I'm
> wondering if I'm doing something wrong.  My relevant code is below.  Thanks
>
> in advance
>
> for key, value in form.cleaned_data.items():
> if key == 'council_district':
> if value.count() > 0:
> if cases == None:
> cases = ZoningCase.objects.filter(councildistrict__in=value)
> else:
> cases = cases.filter(councildistrict__in=value)
> if key == 'cpc':
> case_dates = CaseCPCDate.objects.filter(cpc_meeting=value)
> if case_dates.count() > 0:
> if cases == None:
> cases = ZoningCase.objects.filter(casecpcdate__in=case_dates)
> else:
> cases = cases.filter(casecpcdate__in=case_dates)
> if key == 'cc':
> case_dates = CaseCCDate.objects.filter(cc_meeting=value)
> if case_dates.count() > 0:
> if cases == None:
> cases = ZoningCase.objects.filter(caseccdate__in=case_dates)
> else:
> cases = cases.filter(caseccdate__in=case_dates)
> if key == 'request_type':
> if value.count() > 0:
> if cases == None:
> cases = ZoningCase.objects.filter(zoningrequest__request_type=value)
> else:
> cases = cases.filter(zoningrequest__request_type=value)
> if value is not None and value != '' and value != False and key != 'cpc'
> and key != 'cc' and key != 'council_district' and key != 'request_type':
> if cases == None:
> cases = ZoningCase.objects.filter(**{key: value})
> else:
> cases = cases.filter(**{key: value})
> if cases != None:
> cases.order_by('case_number')
> for c in cases:
> zoningResults.append(ZoningSearchResult(c))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f6ed6295-4a11-44e2-981d-15be8d1f79c0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp98wKB4Oz0bynrGUOkM5kWythAPxhxcifcAfOnTinhJxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ユーザー登録について

2014-04-27 Thread Joseph Mutumi
Hi there, I think your problem is you have not initialized attendance
that you use at `instance = attendance`. So it is just using the name
of your view function which also happens to be 'attendance' and
showing you that error.

Initialize to model object with the usual:
Attendence_data.objects.get(pk=user_id) or if you are using
djago.shortcuts: get_object_or_404(Attendence_data, pk=user_id)

On 4/28/14, hito koto  wrote:
> Ok, Thank you!
>
> this is my models.py:
>
>
> from django.db import models
> from django.contrib.auth.models import User
> #from owner.models import GroupSchedule
>
>
>
> class GroupRestrictionMixin(object):
> group_field = 'group'
>
> def dispatch(request, *args, **kwargs):
> self.request = request
> self.args = args
> self.kwargs = kwargs
>
> obj_group = getattr(self.get_object(), self.group_field)
> user_groups = request.user.groups
>
> if obj_group not in user_groups:
> raise PermissionDenied
>
> return super(GroupRestrictionMixin, self).dispatch(request, *args,
> **kwargs)
>
>
> class User(models.Model):
> user_name = models.CharField(max_length=255, help_text="氏名(名)")
> first_kana = models.CharField(max_length=255, help_text="ふりがな(性)")
> last_kana  = models.CharField(max_length=255, help_text="ふりがな(名)")
> employee_number = models.CharField(blank=True, max_length=22,
> help_text="社員番号")
> gender = models.CharField(max_length=6, choices=(('male',
> '男性'),('female', '女性')), help_text="性別" )
> created_at = models.DateTimeField(auto_now_add=True, help_text="登録日")
>
>
> class Attendance_data(models.Model):
> user = models.ForeignKey(User)
> user_name = models.CharField(max_length=255, help_text="氏名(名)")
> employee_number = models.CharField(blank=True, max_length=22,
> help_text="社員番号")
>
> def __unicode__(self):
> return self.user_name, employee_number
>
> class Leave_work(models.Model):
> user = models.ForeignKey(User)
> user_name = models.CharField(max_length=255, help_text="氏名(名)")
> employee_number = models.CharField(blank=True, max_length=22,
> help_text="社員番号")
>
> def __unicode__(self):
> return self.user_name, employee_unmber
>
> this is my Views.py:
>
> def staff_data(request, user_id=1):
> user = get_object_or_404(User, pk=user_id)
> return render_to_response("staff_data.html",
>  {"user": User.objects.get(id=user_id) })
>
> def attendance(request, user_id):
> if request.method == "POST":
>
> form = Attendance_dataForm(request.POST, instance = attendance)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect('/articles/get/%s' % user.id)
> else:
> form = Attendance_dataForm()
> args = {}
> args.update(csrf(request))
> args['form'] = form
> return render_to_response('staff_data.html', args,  context_instance =
> RequestContext(request, {'form': form}))
>
> def leave_work(request, user_id):
> if request.method == "POST":
> form = Leave_workForm(request.POST, instance = leave_work)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect('/articles/get/%s' % user.id)
> else:
> form = Leave_workForm()
> c = {}
> c.update(csrf(request))
> c['form'] = form
> return render_to_response('staff_data.html', c,  context_instance =
> RequestContext(request, { 'form': form}))
>
> this is my forms.py:
>
> class ArticleForm(forms.ModelForm):
>
> class Meta:
> model = User
> fields = ('user_name','first_kana', 'last_kana',
> 'employee_number','birthday')
> user_name = forms.CharField(label="氏名", error_messages={'required':
> ''}, help_text='必須')
> first_kana =
> forms.CharField(label="ふりがな(性)",error_messages={'required': ''},
> help_text='必須')
> last_kana = forms.CharField(label="ふりがな(名)",error_messages={'required':
>
> ''}, help_text='必須')
> employee_number = forms.CharField(label="社員番号", required=False)
> birthday = forms.CharField(label="生年月日", required=False)
>
> class Attendance_dataForm(forms.ModelForm):
>
> class Meta:
> model = Attendance_data
> fields = ('user_name','employee_number')
>
> user_name = forms.CharField(label="氏名", error_messages={'required':
> ''}, help_text='必須')
> employee_number =
> forms.CharField(label="社員番号",error_messages={'required': ''},
> help_text='必須')
>
> class Leave_workForm(forms.ModelForm):
>
> class Meta:
> model = Leave_work
> fields = ('user_name', 'employee_number')
> user_name = forms.CharField(label="氏名", error_messages={'required':
> ''}, help_text='必須')
> employee_number = forms.CharField(label="社員番号",
> error_messages={'required': ''}, help_text='必須')
>
> and this is my staff_data.html:
>
> 
> {% csrf_token %}
> 
> 
> 
>ttendance 
> 
>   
> 
> 
>
> 
> {% csrf_token %}
> 
>  type="

Re: Django Queries

2018-05-11 Thread Joseph Mutumi
Hello,

That's strange what does your people model look like? Notice it
will only populate the fields you have defined in the model not
the columns of the table in the database.

Did you run migrations after adding new fields to the model?
$ python manage.py migrate

Kind regards

On Sat, May 12, 2018 at 5:15 AM, Gerald Brown  wrote:

> Greetings:
>
> I have just started to use Django Queries and I am having some problems.
>
> When i use the query: "p = People.objects.all()" & then "p" it shows just
> the lastname & firstname fields even though there are many more fields in
> the table.
>
> I thought ALL means ALL, ALL fields & ALL records!!!
>
> Only 2 records so far in the DB and it shows both of them so ALL RECORDS
> is working.
>
> Another table I have has a date field and a ForeignKey to the people table
> plus some additional fields.  The query returns the date and the firstname
> and lastname from the people table ONLY.
>
> It looks like it is only showing the first two fields in the table.
>
> Any ideas on how I can get it to show ALL fields?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/7e90ad4d-bffe-5690-2559-ec4655fc79b6%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp8%2B4gx6_MOoXT-JAsbq4nbZLAZj%3DTL8MDMd%2Bg_oQwip2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Queries

2018-05-11 Thread Joseph Mutumi
Hello,

You need to clearly understand Python objects because the ORM maps fields
directly to that.

Please check out: https://docs.djangoproject.com/en/2.0/topics/db/queries/

So if you print out the object as a string i.e.

people = People.objects.al()
print people

OR

person = People.objects.get(pk=1)
print person

The string returned by the __str__ or __unicode__ method is what is
displayed.
To access other columns you need to access the attributes like:
person.address
or person.occupation. Through foreign keys too e.g. person.town.name.

Read through the docs and follow those examples first. You'll easily
understand
thereafter.

Kind regards

On Sat, May 12, 2018 at 9:12 AM, Gerald Brown  wrote:

> I was getting the same as you are as I had just first_name & last_name set
> in the "def __str__(self)".  I added a couple of more fields to that
> statement but they are still not showing up even after running a
> makemigration which says "No Change"
>
> I tried "p.address" but it gave me an error message, (which I don't
> remember) as I did not know about the "[]"s.  Now if I do "p.[0].address"
> it gives me the address. Also if I do "p[0].town" it show me the town name,
> which is in another table and is a FK to that table.
>
> Like I said in my original message, I am just starting to use Django
> Queries so there is a lot to learn so I thank you for your assistance.
>
> On Saturday, 12 May, 2018 01:34 PM, Mark Phillips wrote:
>
> Please provide the exact output you are seeing. It may be that the output
> has been truncated, which is correct behavior.
>
> For example, when I run this query on the command line for my model
> Document,
>
> >>> Document.objects.all()
> , ,  gg>, ]>
>
> I get a QuerySet with 4 entries, as there are 4 rows/records in the
> Document table. All the fields are there, just not shown. The __str__
> method in the Document model returns the title of the document, which is
> what is shown above for each Document in the QuerySet. I am guessing but
> your People table probably defines the __str__ method to return the first
> and last name.
>
> I can look at one of the returned rows like this:
>
> >>> d=Document.objects.all()
> >>> d[0]
> 
> >>> d[0].document_id
> 2
> >>> d[0].title
> 'a new title 2'
> >>> d[0].description
> 'a new description 2'
> >>> d[0].document_state
> 1
> >>> d[0].storage_file_name
> 
> >>>
>
> title, document_id, description, and storage_file_name are all fields
> defined in the model for Document (along with others).
>
> Read the django documentation about models and queries for more
> information.
>
> Mark
>
> On Fri, May 11, 2018 at 9:34 PM, Joseph Mutumi  wrote:
>
>> Hello,
>>
>> That's strange what does your people model look like? Notice it
>> will only populate the fields you have defined in the model not
>> the columns of the table in the database.
>>
>> Did you run migrations after adding new fields to the model?
>> $ python manage.py migrate
>>
>> Kind regards
>>
>> On Sat, May 12, 2018 at 5:15 AM, Gerald Brown 
>> wrote:
>>
>>> Greetings:
>>>
>>> I have just started to use Django Queries and I am having some problems.
>>>
>>> When i use the query: "p = People.objects.all()" & then "p" it shows
>>> just the lastname & firstname fields even though there are many more fields
>>> in the table.
>>>
>>> I thought ALL means ALL, ALL fields & ALL records!!!
>>>
>>> Only 2 records so far in the DB and it shows both of them so ALL RECORDS
>>> is working.
>>>
>>> Another table I have has a date field and a ForeignKey to the people
>>> table plus some additional fields.  The query returns the date and the
>>> firstname and lastname from the people table ONLY.
>>>
>>> It looks like it is only showing the first two fields in the table.
>>>
>>> Any ideas on how I can get it to show ALL fields?
>>>
>>> Thanks.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this

Re: Creating Reports in Django Admin Panel

2018-06-04 Thread Joseph Mutumi
Hello,

You'll first need to create a custom admin page. Create your view and add
it to the urls.py like normal.

Then you extend the admin base template and display your aggregation in
there:

{% extends "admin/base_site.html" %} {% block title %}Stats title{%
endblock %} {% block content %}Stats HTML{% endblock %}

The you aggregate what you need in the view function and pass that. You'll
need to have the relevant
data counters before hand though. You might want to checkout signals to
implement that?
https://docs.djangoproject.com/en/2.0/topics/signals/

Kind regards

On Sat, Jun 2, 2018 at 6:23 AM, Mukul Mantosh 
wrote:

> How to create a report in  django-admin panel of number of users added to
> the database in a day, week and month. Also, how many API calls for every
> particular API has been made in a day, week and month.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/cde57aba-e168-4c74-97b9-7e4b3a48458c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp9953zu9rF939qTiVxpOMFZGfe6OYxOFZKagOTG%2BMct8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: one-to-one GenericRelation best practices

2018-06-04 Thread Joseph Mutumi
Hello,

May be you want to subclass GenericForeignKey:

class GenericOneToOne(GenericForeignKey):
many_to_one = False
one_to_many = False
one_to_one = True

Though have not tried it so YMMV.

Kind regards

On Thu, May 31, 2018 at 8:59 PM, Vitor Barbosa  wrote:

> Hello! This is my first question, so please excuse any mistakes.
>
> I'm using django 1.8 (working on migration to 2.0).
>
> I need to implement a one-to-one generic relation. To illustrate suppose I
> have three classes, the first representing and abstract class in a store
> and the other specific products which need extra information:
>
>
> AbstractProduct(models.Model):
> 
> sale = GenericRelation('Sales')
> class Meta:
> abstract = True
>
> Books(AbstractProduct):
> 
>
> Magazines(AbstractProduct):
> 
>
>
> Now I need to create a models for 'Sales'. Each sale is of a specific
> product. Following https://docs.djangoproject.com/en/2.0/ref/contrib/
> contenttypes/#generic-relations I used:
>
> class Sales(models.Model):
> 
> content_type = models.ForeignKey(...)
> object_id = models.PositiveIntegerField(...)
> content_object = GenericForeignKey('content_type', 'object_id')
>
>
> My problem is that by using this approach whenever I do
>
> >>> Books.objects.get(pk=1).sale
>
> I get back a manager since django does not know it is a one-to-one
> relation. And it makes me think that maybe I'm approaching this in the
> wrong way.
>
> My question is:
> (a) is this design a good solution for this problem? Is there a better
> approach? Has anyone solved a similar problem in a better way?
> (b) is there a way to create a generic One-To-One relation?
>
> I'm open to answers pointing to good blogs/books/articles which give a
> more formal approach to this kind of design issue, if you know a good one.
>
> Thanks in advance! Yours,
>
> Vitor.
>
>
> --
> Vitor Quintanilha Barbosa
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/CAB-MUC7h4S32XE8nj7%2BtpeYdv%3DtH%3DQBX3ghx
> 0rVxU%2BF0mTAakg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp-rArqkLYuZz3juofd4OzK4qCq8ehnzPB4Ws9zOQpj1Jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flask-supermarket forms creation

2018-06-04 Thread Joseph Mutumi
Hello,

Check Django formset documentation:
https://docs.djangoproject.com/en/2.0/topics/forms/formsets/

For Flask, if you are using WTForms check the using the combination
of FieldList with FormField:
http://wtforms.simplecodes.com/docs/0.6/fields.html#field-enclosures

Though this is a Django discussion forum!

Kind regards

On Tue, May 29, 2018 at 10:47 AM, subhani shaik 
wrote:

> Hi..
> group members.
>
> i am creating supermarket forms using flask and python with the help of
> jquery and ajax.but the problem is how can i design multiple forms.please
> give me suggestions.or else please give me the multiple forms.
>
>
> my form is like this
>
>
> Redumptionid
> userid
> receiptno
>
>
> like this multiple forms..
>
>
>
>
>
> please help me.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/2b7acdec-9ff7-4513-acdb-dcc04436501d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp_PptkfAa1whbQWo6oNAF2UQ5KZbSuL62W98YWnTiP4WQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error running WSGI application

2018-06-04 Thread Joseph Mutumi
Hello,

Check
https://help.pythonanywhere.com/pages/DebuggingImportError/#django-specific-issues

And make sure your directory structure is as recommended:

/home/myusername
`-- myproject/
|-- __init__.py
`-- myproject/
|-- __init__.py
`-- settings.py

If it is not, then correct the sys.path.append(path) in your wsgi file to
where ever it is e.g.: sys.path.append(os.path.dirname(path))

Hope it helps.

Kind regards

On Sat, May 26, 2018 at 9:02 PM, Kadir Guloglu 
wrote:

> Hi friends.
>
>
>  Can I help we please. My project getting exception.
>
>
> WSGI File:
>
> import os
>
> import sys
>
>
> path = os.path.expanduser('~/otomabak')
>
> if path not in sys.path:
>
> sys.path.append(path)
>
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'otomabak.settings'
>
>
> from django.core.wsgi import get_wsgi_application
>
> from django.contrib.staticfiles.handlers import StaticFilesHandler
>
> application = StaticFilesHandler(get_wsgi_application())
>
>
>
> Server Error :
>
> 2018-05-26 17:43:02,582: Error running WSGI application
> 2018-05-26 17:43:02,583: ModuleNotFoundError: No module named 
> 'otomabak.settings'
> 2018-05-26 17:43:02,583:   File 
> "/var/www/kadirguloglu_pythonanywhere_com_wsgi.py", line 12, in 
> 2018-05-26 17:43:02,583: application = 
> StaticFilesHandler(get_wsgi_application())
> 2018-05-26 17:43:02,583:
> 2018-05-26 17:43:02,583:   File 
> "/home/kadirguloglu/otomabak/otomabakenv/lib/python3.6/site-packages/django/core/wsgi.py",
>  line 12, in get_wsgi_application
> 2018-05-26 17:43:02,583: django.setup(set_prefix=False)
> 2018-05-26 17:43:02,584:
> 2018-05-26 17:43:02,584:   File 
> "/home/kadirguloglu/otomabak/otomabakenv/lib/python3.6/site-packages/django/__init__.py",
>  line 19, in setup
> 2018-05-26 17:43:02,584: configure_logging(settings.LOGGING_CONFIG, 
> settings.LOGGING)
> 2018-05-26 17:43:02,584:
> 2018-05-26 17:43:02,584:   File 
> "/home/kadirguloglu/otomabak/otomabakenv/lib/python3.6/site-packages/django/conf/__init__.py",
>  line 56, in __getattr__
> 2018-05-26 17:43:02,584: self._setup(name)
> 2018-05-26 17:43:02,584:
> 2018-05-26 17:43:02,584:   File 
> "/home/kadirguloglu/otomabak/otomabakenv/lib/python3.6/site-packages/django/conf/__init__.py",
>  line 43, in _setup
> 2018-05-26 17:43:02,584: self._wrapped = Settings(settings_module)
> 2018-05-26 17:43:02,585:
> 2018-05-26 17:43:02,585:   File 
> "/home/kadirguloglu/otomabak/otomabakenv/lib/python3.6/site-packages/django/conf/__init__.py",
>  line 106, in __init__
> 2018-05-26 17:43:02,585: mod = 
> importlib.import_module(self.SETTINGS_MODULE)
> 2018-05-26 17:43:02,585: ***
> 2018-05-26 17:43:02,585: If you're seeing an import error and don't know why,
> 2018-05-26 17:43:02,585: we have a dedicated help page to help you debug:
> 2018-05-26 17:43:02,585: 
> https://help.pythonanywhere.com/pages/DebuggingImportError/
> 2018-05-26 
>  
> 17:43:02,585: ***
>
>
>
> *Thanks for help*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/560746fa-8d6f-4a45-ae44-43ee8bf53eb6%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN5idp_ZFKzvLtEpxBJpHPgx_TbE8ihKp5zDK7YSwi7e4GmAXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.