authtools: do not create one-to-one profile object on user creation.
Hello,
I am using the authtools plugin to manage the user and its profile in django, but when I create the user, it does not create its profile, I have to go to the admin part of the site and create it manually.
I separated the applications into account and profile.
This is the profiles model:
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
primary_key=True)
slug = models.UUIDField(default=uuid.uuid4, blank=True, editable=False)
email_verified = models.BooleanField("Email verified", default=True)
This is the signal.py, that is inside of the profiles application:
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_profile_handler(sender, instance, created, **kwargs):
if not created:
return
profile = models.Profile(user=instance)
profile.save()
logger.info('New user profile for {} created'.format(instance))
This is the admin.py of the account app:
class UserProfileInline(admin.StackedInline):
model = Profile
class NewUserAdmin(NamedUserAdmin):
inlines = [UserProfileInline]
list_display = ('is_active', 'email', 'name', 'permalink',
'is_superuser', 'is_staff',)
# 'View on site' didn't work since the original User model needs to
# have get_absolute_url defined. So showing on the list display
# was a workaround.
def permalink(self, obj):
url = reverse("profiles:show",
kwargs={"slug": obj.profile.slug})
# Unicode hex b6 is the Pilcrow sign
return format_html('<a href="{}">{}</a>'.format(url, '\xb6'))
admin.site.unregister(User)
admin.site.register(User, NewUserAdmin)
admin.site.register(Profile)
When I signup a user, both the user and the profile objects are created, only they are not linked. Why is that?
Thank you
/r/django
https://redd.it/8q4ob3
Hello,
I am using the authtools plugin to manage the user and its profile in django, but when I create the user, it does not create its profile, I have to go to the admin part of the site and create it manually.
I separated the applications into account and profile.
This is the profiles model:
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
primary_key=True)
slug = models.UUIDField(default=uuid.uuid4, blank=True, editable=False)
email_verified = models.BooleanField("Email verified", default=True)
This is the signal.py, that is inside of the profiles application:
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_profile_handler(sender, instance, created, **kwargs):
if not created:
return
profile = models.Profile(user=instance)
profile.save()
logger.info('New user profile for {} created'.format(instance))
This is the admin.py of the account app:
class UserProfileInline(admin.StackedInline):
model = Profile
class NewUserAdmin(NamedUserAdmin):
inlines = [UserProfileInline]
list_display = ('is_active', 'email', 'name', 'permalink',
'is_superuser', 'is_staff',)
# 'View on site' didn't work since the original User model needs to
# have get_absolute_url defined. So showing on the list display
# was a workaround.
def permalink(self, obj):
url = reverse("profiles:show",
kwargs={"slug": obj.profile.slug})
# Unicode hex b6 is the Pilcrow sign
return format_html('<a href="{}">{}</a>'.format(url, '\xb6'))
admin.site.unregister(User)
admin.site.register(User, NewUserAdmin)
admin.site.register(Profile)
When I signup a user, both the user and the profile objects are created, only they are not linked. Why is that?
Thank you
/r/django
https://redd.it/8q4ob3
reddit
r/django - authtools: do not create one-to-one profile object on user creation.
2 votes and 3 so far on reddit
Modern Database Interfaces For The Command Line (Interview)
https://www.podcastinit.com/dbcli-with-amjith-ramanujam-episode-165/
/r/Python
https://redd.it/8q8v2j
https://www.podcastinit.com/dbcli-with-amjith-ramanujam-episode-165/
/r/Python
https://redd.it/8q8v2j
Podcast.__init__('Python')
Modern Database Clients On The Command Line with Amjith Ramanujam - Episode 165
The command line is a powerful and resilient interface for getting work done, but the user experience is often lacking. This can be especially pronounced in database clients because of the amount of information being transferred and examined. To help improve…
Adding forms dynamically to a Django formset
https://medium.com/@taranjeet/adding-forms-dynamically-to-a-django-formset-375f1090c2b0
/r/django
https://redd.it/8q9dew
https://medium.com/@taranjeet/adding-forms-dynamically-to-a-django-formset-375f1090c2b0
/r/django
https://redd.it/8q9dew
Medium
Adding forms dynamically to a Django formset
Add multiple ordered similar arguments to manage command
I'm trying to build out a command that'll looker similar to this
`python manage.py gen-data primary=10-state with=30-users with=30-visits`
The goal here is to do test-data generation where the command doesn't become crazy for any of our front end devs. That command would do something like create 10 states, create 30 users who live in each state, and create 30 web visits for each of those users.
I know how to do the actual generation of the data, but I can't seem to find out how to handle having the same argument repeated like that.
Any help would be much appreciated.
Solved:
Turns out you can do a list object as a arg
parser.add_argument(
'--with', default=[], dest='withs', action='append',
help="Specify district ids by comma separated list.")
` python manage.py generate_data --model=user --with=Super --with=cali --with=frag --with=ilistice --with=xpial --with=idocious`
`['Super', 'cali', 'frag', 'ilistice', 'xpial', 'idocious']`
/r/django
https://redd.it/8q9scf
I'm trying to build out a command that'll looker similar to this
`python manage.py gen-data primary=10-state with=30-users with=30-visits`
The goal here is to do test-data generation where the command doesn't become crazy for any of our front end devs. That command would do something like create 10 states, create 30 users who live in each state, and create 30 web visits for each of those users.
I know how to do the actual generation of the data, but I can't seem to find out how to handle having the same argument repeated like that.
Any help would be much appreciated.
Solved:
Turns out you can do a list object as a arg
parser.add_argument(
'--with', default=[], dest='withs', action='append',
help="Specify district ids by comma separated list.")
` python manage.py generate_data --model=user --with=Super --with=cali --with=frag --with=ilistice --with=xpial --with=idocious`
`['Super', 'cali', 'frag', 'ilistice', 'xpial', 'idocious']`
/r/django
https://redd.it/8q9scf
reddit
Add multiple ordered similar arguments to manage command • r/django
I'm trying to build out a command that'll looker similar to this `python manage.py gen-data primary=10-state with=30-users with=30-visits` The...
parver: a package to parse and manipulate PEP440 version numbers
https://github.com/RazerM/parver
/r/Python
https://redd.it/8qb4zl
https://github.com/RazerM/parver
/r/Python
https://redd.it/8qb4zl
GitHub
GitHub - RazerM/parver: Parse and manipulate version numbers.
Parse and manipulate version numbers. Contribute to RazerM/parver development by creating an account on GitHub.
[D] Improving Language Understanding with Unsupervised Learning
https://blog.openai.com/language-unsupervised/
/r/MachineLearning
https://redd.it/8qbzom
https://blog.openai.com/language-unsupervised/
/r/MachineLearning
https://redd.it/8qbzom
Getting started with Apache Kafka in Python
http://blog.adnansiddiqi.me/getting-started-with-apache-kafka-in-python/?utm_source=r_python_kafka&utm_medium=reddit&utm_campaign=c_r_python_kafka
/r/Python
https://redd.it/8qe9d9
http://blog.adnansiddiqi.me/getting-started-with-apache-kafka-in-python/?utm_source=r_python_kafka&utm_medium=reddit&utm_campaign=c_r_python_kafka
/r/Python
https://redd.it/8qe9d9
Adnan's Random bytes
Getting started with Apache Kafka in Python
Learn the basics of Kafka and write a sample distributed application in Python.
Web Scrape YouTube channel for video info and a table of contents using Python 3.6 and Beautiful Soup (V1.1)
https://teklern.blogspot.com/2018/06/web-scrape-youtube-channel-for-video.html
/r/Python
https://redd.it/8qds2e
https://teklern.blogspot.com/2018/06/web-scrape-youtube-channel-for-video.html
/r/Python
https://redd.it/8qds2e
Blogspot
Web Scrape YouTube channel for video info and a table of contents using Python 3.6 and Beautiful Soup (V1.1)
I have a YouTube channel for my videos to teach programming and needed to create a nice table of contents for a web page. YouTube alwa...
[P] Simple Tensorflow implementation of StarGAN (CVPR 2018 Oral)
/r/MachineLearning
https://redd.it/8qh7e5
/r/MachineLearning
https://redd.it/8qh7e5
What's everyone working on this week?
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/8qj87y
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/8qj87y
reddit
r/Python - What's everyone working on this week?
1 votes and 1 so far on reddit
JWT Auth with AWS Cognito
How does one get started with using warrant/cognito for flask JWT auth ?
We can login to cognito using warrant and it returns a token, but from there we don't know how to proceed in flask.
https://stackoverflow.com/questions/50801247/python-and-flask-for-authentication-with-amazon-cognito
/r/flask
https://redd.it/8qj3pp
How does one get started with using warrant/cognito for flask JWT auth ?
We can login to cognito using warrant and it returns a token, but from there we don't know how to proceed in flask.
https://stackoverflow.com/questions/50801247/python-and-flask-for-authentication-with-amazon-cognito
/r/flask
https://redd.it/8qj3pp
Stack Overflow
Python and Flask for authentication with Amazon Cognito
Here's the end goal: to write a Flask app that supports login/authentication using Amazon Cognito User Pools. Both frameworks are fairly new to me.
I used warrant serverless authentication to get ...
I used warrant serverless authentication to get ...
Python script I wrote that tells whether it’s a Pizza or Not a Pizza
https://youtu.be/m_S7caqSFxc
/r/Python
https://redd.it/8qh9gf
https://youtu.be/m_S7caqSFxc
/r/Python
https://redd.it/8qh9gf
YouTube
Python image recognition
It’s a simple python script that I wrote it allows us to classify image. In my case I am using Clarifai Api to determine whether the image is pizza or not It...
May Release of Saleor: getting ready for GDPR
https://medium.com/saleor/may-release-of-saleor-getting-ready-for-gdpr-4bcb8c99438d
/r/django
https://redd.it/8qide2
https://medium.com/saleor/may-release-of-saleor-getting-ready-for-gdpr-4bcb8c99438d
/r/django
https://redd.it/8qide2
Medium
May Release of Saleor: getting ready for GDPR
Welcome to the May 2018 release of Saleor!
Celery 4.2.0 released!
http://docs.celeryproject.org/en/master/changelog.html#changelog
/r/Python
https://redd.it/8qj5ez
http://docs.celeryproject.org/en/master/changelog.html#changelog
/r/Python
https://redd.it/8qj5ez
What's the right way to handle these workflows in DRF?
I've never that been that into external APIs. We honestly haven't needed them that much, and when we have, API views written for each situation has both made sense and (obviously) done exactly what we need.
We're planning to open some of our system up to our clients (and their clients). It's essentially a booking system with, amongst other thins, Booking and User Models.
Basic viewsets and permissions are all done. 10 minute job. But there are two operations that I'm finding difficult to translate (in my head as much as anywhere else) into whatever passes for the "proper" way to do in REST.
The first is booking state change. Advancing the booking from EDITING to CONFIRMED or REJECTED or ON_SITE or LEFT_SITE or CANCELLED, etc. There are quite a few. In the "old" views we have logic to say what states some users can go between. There are also availability checks performed when going from EDITING to a confirmed state.
Do I just assume somebody is going to `partial_update` or 'update' the state and I have to validate this? Or should I be abstracting state change to '/bookings/<id>/{cancel,edit,reject,arrived,left}` etc?
The other problem is some views *occasionally* need more data. One example is a user list. Normally the list of users is enough but occasionally we might want to show (even sort) by when a User last had a booking.
In a Django view this is pretty trivial to annotate in. It's an expensive query, but it's trivial. And that's the problem. There are some Viewsets where I don't want all these expensive annotated fields littering the response where they aren't needed.
Do I just hack in a `?booking_data=1`, or *should* I add a separate API view for Users with booking data?
Again, I realise there are many simple things I could do to hack these in but this is intended for an external audience who have to read —and understand— documentation to use our product. I'm conscious that doing everything via hacky querystrings might not give the best impression.
/r/django
https://redd.it/8qkwqv
I've never that been that into external APIs. We honestly haven't needed them that much, and when we have, API views written for each situation has both made sense and (obviously) done exactly what we need.
We're planning to open some of our system up to our clients (and their clients). It's essentially a booking system with, amongst other thins, Booking and User Models.
Basic viewsets and permissions are all done. 10 minute job. But there are two operations that I'm finding difficult to translate (in my head as much as anywhere else) into whatever passes for the "proper" way to do in REST.
The first is booking state change. Advancing the booking from EDITING to CONFIRMED or REJECTED or ON_SITE or LEFT_SITE or CANCELLED, etc. There are quite a few. In the "old" views we have logic to say what states some users can go between. There are also availability checks performed when going from EDITING to a confirmed state.
Do I just assume somebody is going to `partial_update` or 'update' the state and I have to validate this? Or should I be abstracting state change to '/bookings/<id>/{cancel,edit,reject,arrived,left}` etc?
The other problem is some views *occasionally* need more data. One example is a user list. Normally the list of users is enough but occasionally we might want to show (even sort) by when a User last had a booking.
In a Django view this is pretty trivial to annotate in. It's an expensive query, but it's trivial. And that's the problem. There are some Viewsets where I don't want all these expensive annotated fields littering the response where they aren't needed.
Do I just hack in a `?booking_data=1`, or *should* I add a separate API view for Users with booking data?
Again, I realise there are many simple things I could do to hack these in but this is intended for an external audience who have to read —and understand— documentation to use our product. I'm conscious that doing everything via hacky querystrings might not give the best impression.
/r/django
https://redd.it/8qkwqv
reddit
r/django - What's the right way to handle these workflows in DRF?
2 votes and 3 so far on reddit
[D] Keys to compete against industry when in academia
It seems from published papers that state\-of\-the\-art results are always coming out from industry, and that makes sense because of the much stronger compute power typically available in companies vs. universities. Traditionally, it is somewhat expected that university researchers should focus more on ideas and concepts while industry researchers should consider large scale implementations. However, one observation at recent NIPS/ICML/ICLR/CVPR/etc.. papers reveals a common trend of showing off empirical results. This has haunted me several times and resulted in papers being rejected. It is just too hard to generate empirical results as awesome as those from industry. I hence focus on the more theoretical and algorithmic aspects, but it gets so frustrating when reviewers only critique the empirical results. My question is how to compete with industry in the era where empiricism is becoming so strong in machine learning?
/r/MachineLearning
https://redd.it/8qmhmo
It seems from published papers that state\-of\-the\-art results are always coming out from industry, and that makes sense because of the much stronger compute power typically available in companies vs. universities. Traditionally, it is somewhat expected that university researchers should focus more on ideas and concepts while industry researchers should consider large scale implementations. However, one observation at recent NIPS/ICML/ICLR/CVPR/etc.. papers reveals a common trend of showing off empirical results. This has haunted me several times and resulted in papers being rejected. It is just too hard to generate empirical results as awesome as those from industry. I hence focus on the more theoretical and algorithmic aspects, but it gets so frustrating when reviewers only critique the empirical results. My question is how to compete with industry in the era where empiricism is becoming so strong in machine learning?
/r/MachineLearning
https://redd.it/8qmhmo
reddit
[D] Keys to compete against industry when in... • r/MachineLearning
It seems from published papers that state\-of\-the\-art results are always coming out from industry, and that makes sense because of the much...
Somebody please help me convert some url patterns to the newer "path" syntax
So I was following what I thought was a Django 2.0 tutorial until we got [to this part](http://muva.co.ke/blog/lesson-4-defining-url-patterns-template-shop-products-django-2-0-python-3-6/) where I just couldn't continue because I can't understand how to read those URL patterns. I'm new to Django and only wanna consider the new "path" syntax for urls. Anyway, would somebody be kind enough to convert the patterns in the linked tutorial to be in the new syntax? By the way, I didn't expect this, had been getting along with what I thought was a version 2.0 tutorial, but oh, well.
/r/django
https://redd.it/8qnoy1
So I was following what I thought was a Django 2.0 tutorial until we got [to this part](http://muva.co.ke/blog/lesson-4-defining-url-patterns-template-shop-products-django-2-0-python-3-6/) where I just couldn't continue because I can't understand how to read those URL patterns. I'm new to Django and only wanna consider the new "path" syntax for urls. Anyway, would somebody be kind enough to convert the patterns in the linked tutorial to be in the new syntax? By the way, I didn't expect this, had been getting along with what I thought was a version 2.0 tutorial, but oh, well.
/r/django
https://redd.it/8qnoy1
We Create, You Like! | Muva Blog, Kenya
Lesson 4: Defining Url patterns and template for Our Shop products in Django 2.0 and Python 3.6
Hey, this is Henry Mbugua again with the fourth lesson of our ecommerce shop project series. In this section we…
Google is finally working on Python 3 for the App Engine Standard Environment
https://issuetracker.google.com/issues/35876441#comment104
/r/Python
https://redd.it/8qlwvy
https://issuetracker.google.com/issues/35876441#comment104
/r/Python
https://redd.it/8qlwvy
reddit
r/Python - Google is finally working on Python 3 for the App Engine Standard Environment
94 votes and 12 so far on reddit
r/RoguelikeDev is running a summer dev-along tutorial series in python
Interested in making a traditional turn-based roguelike? Want to do it alongside other devs and beginners with a tutorial? Over at r/roguelikedev we're starting a [weekly summer event](https://i.imgur.com/EYJFgdI.png) on June 19th where you can do just that :D
Check out "[RoguelikeDev Does The Complete Roguelike Tutorial](https://www.reddit.com/r/roguelikedev/comments/8ql895/roguelikedev_does_the_complete_roguelike_tutorial/)" for more info, including the planned schedule.
The main tutorial we'll be following is in python, although some participants may opt to use other languages.
/r/Python
https://redd.it/8qnlcm
Interested in making a traditional turn-based roguelike? Want to do it alongside other devs and beginners with a tutorial? Over at r/roguelikedev we're starting a [weekly summer event](https://i.imgur.com/EYJFgdI.png) on June 19th where you can do just that :D
Check out "[RoguelikeDev Does The Complete Roguelike Tutorial](https://www.reddit.com/r/roguelikedev/comments/8ql895/roguelikedev_does_the_complete_roguelike_tutorial/)" for more info, including the planned schedule.
The main tutorial we'll be following is in python, although some participants may opt to use other languages.
/r/Python
https://redd.it/8qnlcm