replacing existing file with new uploaded file

2017-07-11 Thread sum abiut
Hi all,
need some directions, i need direction replacing file with newly uploaded
file. The upload function is working but i want to replace a file every
time i upload a new one.


my model.py

class uploadfile(models.Model):
description = models.CharField(max_length=255, blank=True)
Select_File=models.FileField(upload_to='/var/www/projects/webapp/media')
uploaded_at =models.DateTimeField(auto_now_add=True)


my view.py

def uploadfunc(request):
if request.method=='POST':
form =uploadfileform(request.POST,request.FILES)
if form.is_valid():
form.save()
return render_to_response('upload_successful.html')
else:
form=uploadfileform()
return render(request, 'upload.html',{'form':form})

-- 
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/CAPCf-y4PfafDi-2fUhMdjP9KhRuahdTbD3sy64b8PbQjx%3D0HVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Travelling & Open Source Contributions

2017-07-11 Thread Mehul Sharma
Hi Everyone,

I've been working on Django for about 3 Months now and I have developed and
deployed some applications in Heroku too.
Due to my experience in python it was easy to get going with django because
if its beautiful community.
I am now looking to make open source contributions to some organisations​
so as to further concrete my concepts and also help me travel the world as
I learn and travel and learn and help.

I request you to kindly suggest me some ways through which I can contribute
to communities and they can help me travel the world.

I think this is a question for which everyone would want to hear the answer.

I'll be thankful.

-- 
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/CAMrcPx0F0h-u4Dek9s15q-1P1tb0c119miQQ%3DoxRTBZOEt%3D4Eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Defining project apps

2017-07-11 Thread Rich Shepard

On Tue, 11 Jul 2017, yingi keme wrote:


I don't think you will have any app conflicts if you give them names
applying to the content of the app or any other name that suites you best.


Yingi,

  I want to avoid Django reserved words if any exist. Both python and SQL
have reserved words so variables, classes, attributes, etc. do not use those
names. If Django has no issues with naming apps 'client_data' and 'reports'
I'll use those names because they clearly express their purpose.

Thanks,

Rich




Re: Defining project apps

2017-07-11 Thread yingi keme
I dont think you will have any app conflicts if you give them names applying to 
the content of the app or any other name that suites you best. 
Yes Ofcourse you should avoid name conflicts as regards to naming the apps 
within the project. But on the purpose of github, maybe you should be concerned 
about project names.

Yingi Kem

> On 11 Jul 2017, at 7:54 PM, Rich Shepard  wrote:
> 
>  My background is database applications, not web site, development so I
> have started my first django-1.11.3 project by defining the database schema
> and defining the classes in models.py. Now I want to define the app based on
> this file and am not sure how to name it.
> 
>  This project is for my own use, a client relation management application
> (which will go to github when done). I want to avoid name conflicts with app
> names so my first inclination is to define one app as data and another as
> reports.
> 
>  Please suggest appropriate app names if these would be problematic.
> 
> Rich

-- 
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/340C57A0-E893-490A-9B53-E3165284D945%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Defining project apps

2017-07-11 Thread Rich Shepard

  My background is database applications, not web site, development so I
have started my first django-1.11.3 project by defining the database schema
and defining the classes in models.py. Now I want to define the app based on
this file and am not sure how to name it.

  This project is for my own use, a client relation management application
(which will go to github when done). I want to avoid name conflicts with app
names so my first inclination is to define one app as data and another as
reports.

  Please suggest appropriate app names if these would be problematic.

Rich


Re: how to display a foreign key image of an object in an object_list view/template?

2017-07-11 Thread ecas
There was a typo:

products = Product.objects.all()
for product in products:
product.image = product.productimages_set.first()


Other than that, it should work. You could try this in the django shell, 
just to verify the reverse name of the relationship.

from your_app.models import *
product=Product.objects.first()
product.productimages_set.first()

And debug from there.

El dimarts, 11 juliol de 2017 16:20:00 UTC+2, Bledi va escriure:
>
> Thanks, but I am getting this error:
>
> 'Product' object has no attribute 'productimages_set'
>
>
>
> On Tuesday, July 11, 2017 at 5:29:15 AM UTC-4, ecas wrote:
>>
>>
>> You can query for the images, and keep the first one for the template 
>> rendering.
>>
>> products = Product.objects.all()
>> for product in products:
>> products.image = product.productimages_set.first()
>>
>>
>>
>>
>>

-- 
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/ef17071e-e27e-43ba-a012-729372af518e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to display a foreign key image of an object in an object_list view/template?

2017-07-11 Thread Bledi
Thanks, but I am getting this error:

'Product' object has no attribute 'productimages_set'



On Tuesday, July 11, 2017 at 5:29:15 AM UTC-4, ecas wrote:
>
>
> You can query for the images, and keep the first one for the template 
> rendering.
>
> products = Product.objects.all()
> for product in products:
> products.image = product.productimages_set.first()
>
>
>
>
>

-- 
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/bbb52ba2-0dbd-4965-a285-95a410acdf5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


facebook share

2017-07-11 Thread ADEWALE ADISA
hi guys,
I am having issues with django-social-share. Am trying to add facebook
share to my django app using django-social-share, but the issue is i just
want to share a section of my page like div or article.
The problem is its share the whole page on facebook instead of section.
Please any help ?

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/msgid/django-users/CAMGzuy9QcKgrFBGLQyipcMGoyOnMaNcCTu-CUStoQY7fKOLKAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Use one correspondig database user for each application user

2017-07-11 Thread guettli
Thank you for your answer. Yes, I use one database user since several 
years, and I guess it will be that way the next years.

Nevertheless I think it is good to talk about things like this from time to 
time.

Regards,
  Thomas

Am Dienstag, 11. Juli 2017 12:11:59 UTC+2 schrieb Antonis Christofides:
>
> Hi,
>
> This was discussed three months ago (the subject was "DATABASE DICTIONARY 
> in Settings.py"), and this was my opinion: 
>
> As you know, RDBMS's keep their own list of users and have sophisticated 
> permissions systems with which different users have different permissions 
> on different tables. This is particularly useful in desktop applications 
> that connect directly to the database. Web applications changed that. 
> Instead of the RDBMS managing the users and their permissions, we have a 
> single RDBMS user as which Django connects to the RDBMS, and this user has 
> full permissions on the database. The actual users and their permissions 
> are managed by Django itself (more precisely, by the included Django app 
> django.contrib.auth), using database tables created by Django. What a user 
> can or cannot do is decided by Django, not by the RDBMS. This is a pity 
> because django.contrib.auth (or the equivalent in other web frameworks) 
> largely duplicates functionality that already exists in the RDBMS, and 
> because having the RDBMS check the permissions is more robust and more 
> secure. I believe that the reason web frameworks were developed this way is 
> independence from any specific RDBMS, but I don't really know.
>
> So the canonical way of working is to have a single *database user* as 
> which Django logs on to the database, with full permissions on the database 
> (including permission to create and delete tables), and many *Django 
> users*, each one with different permissions. Typically only one Django 
> superuser is created. I call the superuser "admin", which I believe is the 
> common practice.
>
> You can probably do things differently, and maybe there exist custom 
> database backends that would allow you to switch the database user on 
> login, but if there's no compelling reason you should really stick to the 
> canonical way.
>
> Regards,
>
> Antonis
>
> Antonis Christofideshttp://djangodeployment.com
>
>
> On 2017-07-11 12:40, guettli wrote:
>
> I guess most applications have exactly one database user.
>
> Why not use one database for each application user?
>
> Example: User "foo" in my web application has a corresponding database 
> user "foo".
>
> This way you could use row level security from the database.
>
> PostgreSQL has a lot of interesting features: 
> https://www.postgresql.org/docs/devel/static/ddl-rowsecurity.html
>
> Use case: Show me all items which user "foo" is allowed to see.
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/7d1eaa8c-d80a-4390-aaf9-8a95d3fcf6b4%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/7eae0e90-ce51-467f-a492-812da1a6ef62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Use one correspondig database user for each application user

2017-07-11 Thread guettli


Am Dienstag, 11. Juli 2017 11:46:41 UTC+2 schrieb Avraham Serour:
>
> Where would you store the password hashes?
>
>
I see several possible ways.

 1. use django.contrib.auth for authentication like before. The initial 
connection to the db gets done via a database-superuser. After auth in 
django the db-user gets changed.
 2. Forward authentication to postgres ... 
  ...


 
 

> This would mean that no data ever could have relations between users
>
>
Do you mean this:

item1 can be viewed by user1. Item2 can be viewed by user2. User1 can not 
see item2 and user2 can not see item1. Then you can't have or can't resolve 
a ForeignKey from item1 to item2

Is this what you mean?

 

-- 
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/44a56508-3ca8-451b-a98a-79c3cd83e2d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django implementation group by every two hours,

2017-07-11 Thread kanhaiya yadav
Hi,

I have a model 
class XyzModel (models.Model):
   name = models.CharField(max_length=NAME_LENGTH)
   unique_id = models.CharField(max_length=NAME_LENGTH)
   info = models.CharField(max_length=NAME_LENGTH, blank=True)
   violation_time = models.DateTimeField()




I have many rows in the database. So I want to group by the results for 
every two hours or for every four hours.
I want the result something like

name   violation_date   
interval counts
abc   2017-07-01 
 06:00 - 08:00   20
xyz   2017-07-01   
08:00 - 10:00   30

My query is 
XyzModel.objects
.extra({"day": "date_trunc('hour',violation_time)"}
.values("day")
.order_by("day")
.annotate(count=Count("id"))
But using this query I can only group the result by one hour interval. I 
want to group by more than one hour interval.

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/msgid/django-users/93e8965b-b2d3-4567-8f74-6004751ede16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Use one correspondig database user for each application user

2017-07-11 Thread Antonis Christofides
Hi,

This was discussed three months ago (the subject was "DATABASE DICTIONARY in
Settings.py"), and this was my opinion:

As you know, RDBMS's keep their own list of users and have sophisticated
permissions systems with which different users have different permissions on
different tables. This is particularly useful in desktop applications that
connect directly to the database. Web applications changed that. Instead of
the RDBMS managing the users and their permissions, we have a single RDBMS
user as which Django connects to the RDBMS, and this user has full
permissions on the database. The actual users and their permissions are
managed by Django itself (more precisely, by the included Django app
django.contrib.auth), using database tables created by Django. What a user
can or cannot do is decided by Django, not by the RDBMS. This is a pity
because django.contrib.auth (or the equivalent in other web frameworks)
largely duplicates functionality that already exists in the RDBMS, and
because having the RDBMS check the permissions is more robust and more
secure. I believe that the reason web frameworks were developed this way is
independence from any specific RDBMS, but I don't really know.

So the canonical way of working is to have a single *database user* as which
Django logs on to the database, with full permissions on the database
(including permission to create and delete tables), and many *Django users*,
each one with different permissions. Typically only one Django superuser is
created. I call the superuser "admin", which I believe is the common 
practice.

You can probably do things differently, and maybe there exist custom
database backends that would allow you to switch the database user on login,
but if there's no compelling reason you should really stick to the canonical
way.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2017-07-11 12:40, guettli wrote:
> I guess most applications have exactly one database user.
>
> Why not use one database for each application user?
>
> Example: User "foo" in my web application has a corresponding database user 
> "foo".
>
> This way you could use row level security from the database.
>
> PostgreSQL has a lot of interesting features:
> https://www.postgresql.org/docs/devel/static/ddl-rowsecurity.html
>
> Use case: Show me all items which user "foo" is allowed to see.
> -- 
> 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/7d1eaa8c-d80a-4390-aaf9-8a95d3fcf6b4%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/31981958-2d3e-6c02-eb57-0817676be6d0%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Use one correspondig database user for each application user

2017-07-11 Thread Avraham Serour
Where would you store the password hashes?

This would mean that no data ever could have relations between users

On Tue, Jul 11, 2017 at 12:40 PM, guettli  wrote:

> I guess most applications have exactly one database user.
>
> Why not use one database for each application user?
>
> Example: User "foo" in my web application has a corresponding database
> user "foo".
>
> This way you could use row level security from the database.
>
> PostgreSQL has a lot of interesting features: https://www.postgresql.org/
> docs/devel/static/ddl-rowsecurity.html
>
> Use case: Show me all items which user "foo" is allowed to see.
>
> --
> 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/7d1eaa8c-d80a-4390-aaf9-8a95d3fcf6b4%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/CAFWa6t%2BM1VZkKp1wky%2BN42y-vW0vWMtod64zcm7%2BfzGPP%2B4a-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Use one correspondig database user for each application user

2017-07-11 Thread guettli
I guess most applications have exactly one database user.

Why not use one database for each application user?

Example: User "foo" in my web application has a corresponding database user 
"foo".

This way you could use row level security from the database.

PostgreSQL has a lot of interesting features: 
https://www.postgresql.org/docs/devel/static/ddl-rowsecurity.html

Use case: Show me all items which user "foo" is allowed to see.

-- 
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/7d1eaa8c-d80a-4390-aaf9-8a95d3fcf6b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to display a foreign key image of an object in an object_list view/template?

2017-07-11 Thread ecas

You can query for the images, and keep the first one for the template 
rendering.

products = Product.objects.all()
for product in products:
products.image = product.productimages_set.first()




-- 
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/ea2caaf4-7cdf-450d-973b-23fefc82018a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create a fixed-length binary field with a unique constraint?

2017-07-11 Thread ecas
I would use:

fingerprint_sha256 = models.CharField(max_length=64, unique=True, 
db_index=True)

In hexadecimal, a SHA-256 uses 64 characters (4 bits per char).
The ASCII of the characters used in the hexadecimal representation are 1 
byte in UTF-8 (0-9, a-f).

-- 
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/b6734947-ecec-4983-9253-57f1d95f13f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.