These are chat archives for django/django

Jun 2018
Jun 22 2018 03:58

At your Game model

creator = models.ForeignKey('CustomUser', blank=True, related_name='games', on_delete=models.CASCADE)

I recommend adding related_query_name='games' into it too.
Assume you know how to inherit ModelSerializer

class GameSerializer(serializers.ModelSerializer):
    creator = CustomUserSerializer(many=True)

    class Meta:
        model = Game
        fields = [
Paul A. Aranguren
Jun 22 2018 05:13
I was able to solve my previous problem a couple of days ago, thnks guys.
Garrus Napp
Jun 22 2018 07:14
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        fields = (
        model = CustomUser
class GameSerializer(serializers.ModelSerializer):
    creator = UserSerializer(read_only=True)

    class Meta:
        model = Game
        fields = ("id", "creator", "players_count", "started", "finished", "draw", "surrendered", "board")
there's only one creator so I didn't use many
But I get the keyError now :(
Garrus Napp
Jun 22 2018 08:13
@elcolie solved, I wasn't passing correct thing to serializer in views. Thank you!!
Jun 22 2018 08:42
Glad you solved it
Jun 22 2018 09:41
I have a question about OAuth
I can separate the Provider and Resource server
But I want to extend the feature
I wants email/password authentication
Here is my question
Megh Thakkar
Jun 22 2018 09:43
@elcolie so you want to verify the email using OAuth and then login the user using the same, right?
Jun 22 2018 09:50
On the last line of creating the instance it is my and I could not be able to connect the program to one working system.
    'SCOPES': {
        # 'users': 'user details',
        'read': 'Read scope',
        'write': 'Write scope',
        # 'groups': 'Access to your groups',
        'mp_resource': 'MP Resource Server',
        'introspection': 'introspection',
    'ACCESS_TOKEN_EXPIRE_SECONDS': 86400,  # 1 Day.
I don't have any class in the nor the rest of the config
Megh Thakkar
Jun 22 2018 09:54

What I did for my project was use client side authentication from google oauth2. It returns a token on the front end side, which can be analysed

token = request.POST['id_token']
idinfo = id_token.verify_oauth2_token(token, oauth_requests.Request(), OAUTH_CLIENT_ID)
if idinfo['iss'] not in ['', '']:
    context = {
        'error_heading': "Invalid user.",
        'message': "Sorry! Your user hasn't been activated yet.",
    return render(request, '<app_name>/message.html', context)
email = idinfo['email']

I used the following two imports:

from google.oauth2 import id_token
from google.auth.transport import requests as oauth_requests

and OAUTH_CLIENT_ID is generated using the Google API.

The id_token is the token that Google Client Side authentication returns
Then, you can query users or create new ones from the email obtained, which will be a verified gmail email ID
In the django.contrib.auth User model as required
Jun 22 2018 10:08
@Megh-Thakkar Thank you for your reply. I have Provider and Resource server on my own.
I did not rely on any of 3rd parties.
Megh Thakkar
Jun 22 2018 10:13
:smile: @elcolie
@elcolie you can always send a verification mail, with a UUID token! And upon verification, make the user active, until then it is inactive.
Just that it can prove tiresome to the client, and nowadays, it is a bad sign
Jun 22 2018 13:12
@elcolie won't it show items in dropdown for posting product to the cart?
Because for adding items to cart, only product and quantity is needed.
Jun 22 2018 15:21
If your has M2M fields and serializers Meta class has it in the fields. It will not be dropdown. It will be multiple selections like group and permissions.
Anyway could you show me your
Jun 22 2018 15:27
Jun 22 2018 15:28
class CartSerializer(serializers.ModelSerializer):
    user = serializers.CurrentUserDefault()
    items = CycleSerializer(many=True, read_only=True)

    class Meta:
        model = Cart
        fields = ['user', 'items', 'subtotal']
class Cart(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)
    items = models.ManyToManyField(Cycle, through='CartItem')
    subtotal = models.DecimalField(max_digits=50, decimal_places=2, default=0.00)
    tax_percentage = models.DecimalField(max_digits=10, decimal_places=5, default=0.085)
    tax_total = models.DecimalField(max_digits=50, decimal_places=2, default=0.00)
    total = models.DecimalField(max_digits=50, decimal_places=2, default=0.00)
    objects = CartManager()

class CartItem(models.Model):
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
    item = models.ForeignKey(Cycle, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)
    line_item_total = models.DecimalField(max_digits=10, decimal_places=2)
Jun 22 2018 16:41
hello everyone! I accidently broke python - I did "pip uninstall html5lib" , and then when I do "pip install html5lib" it says "Import Error: cannot import name 'html5lib'"
would highly appreciate help on this
arch linux here,python 3.6.5
Jun 22 2018 17:20
@SanskarSans What is Cycle means?
And what is the Cycle model?
@kurwazavr pip freeze and see what you installed
Also check your code and header. I think your header is wrong.
Jun 22 2018 17:30
@elcolie sorry where to look for header?
anything starting with pip gives that very same errot
Sanjeev Sharma
Jun 22 2018 17:40
How can I upload images from admin panel? I have set up the ImageField, but where does it go? It's not working. It's different than form handling as I am uploading from admin side.
Jun 22 2018 18:25
@elcolie I ahve reinstalled it with official python script and now it works, thank you anyways
Luis Gerardo Pacheco Morales
Jun 22 2018 19:01

class CustomLoginForm(LoginForm):
    def __init__(self, *args, **kwargs):
        super(CustomLoginForm, self).__init__(*args, **kwargs)
        # self.fields['password'].widget = forms.PasswordInput()
        self.helper.form_show_labels = False

        helper = FormHelper(form=self)
        helper.form_show_labels = False
        helper.layout = Layout(
            Div('login', css_class="deste"),
            Div('password', css_class="deste"),
                <button id="guardar" href="" type="submit" value="Guardar" class="btn btn-primary mt-2 col-3"><i class="fas fa-sign-in-alt"></i> Regístrate</button>
        # self.helper = helper

    # def login(self, request, user):
        # = self.cleaned_data('email')
        # user.password = self.cleaned_data('password')
Sup guys. I'm trying to override my login form cause i got to change the field css class but when i run it i get a 'str' object has no attribute 'get' error i never tried overriding the login forms so idk what to do
Salar Rahmanian
Jun 22 2018 23:36
so I am sending a signal - in my code the receives message fine, if I have the same receiver included in a test for testing it never receives it though when the test run the receiver in the app itself works
any ideas on why this is happening to me? Am I crazy? :-)