how to copy data per user

27 views
Skip to first unread message

Jun Tanaka

unread,
Oct 7, 2015, 5:00:56 AM10/7/15
to Django users
Hello all!

I use Django 1.6
I would like to copy data from one user to another. Say user 1 has data_set_A in database and I would like to copy data_set_A to user 2, user3, user4. 
If you could tell me any simple way to do so, I would appreciate it.

Thank you,
 
Jun

Tim Graham

unread,
Oct 7, 2015, 8:36:59 AM10/7/15
to Django users
I don't think you've provided enough details about your models for anyone to provide an answer.

p.s. Django 1.6 is unsupported and has unfixed security vulnerabilities so you should try to upgrade to a supported version.
https://www.djangoproject.com/download/#supported-versions

Jun Tanaka

unread,
Oct 8, 2015, 3:19:02 AM10/8/15
to Django users
Hello Tim,

2015年10月7日水曜日 21時36分59秒 UTC+9 Tim Graham:
I don't think you've provided enough details about your models for anyone to provide an answer.

Probably, you are right. Simply, any model with below for per users is fine. 
from django.contrib.auth.models import User


Say something like,

from django.db import models
from django.contrib.auth.models import User
     
class UserProfile(models.Model):
    url = models.URLField()
    home_address = models.TextField()
    phone_numer = models.PhoneNumberField()
    user = models.ForeignKey(User, unique=True)


 
p.s. Django 1.6 is unsupported and has unfixed security vulnerabilities so you should try to upgrade to a supported version.
https://www.djangoproject.com/download/#supported-versions


Thank you for pointing it. 

Stephen J. Butler

unread,
Oct 8, 2015, 4:27:59 AM10/8/15
to django...@googlegroups.com
Lots of ways to do it. Maybe most efficient is:

UserProfile.objects.filter(user__in=u_dst).update(url=up_src.url, home_address=up_src.home_address, phone_number=up_src.phone_number)

Where u_dst is a list/tuple/iterable of destination users, and up_src is the UserProfile of the source user.

--
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 discussion on the web visit https://groups.google.com/d/msgid/django-users/6e998fda-8cb3-4c33-b7d3-fae5ef749c0b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages