Tuesday, July 11, 2023

Re: Django Channels with Queue (Lobby) Manager

Nicee

On Tue, Jul 11, 2023, 11:56 AM Alex R <alexrebrikme@gmail.com> wrote:
Hello dear Community!

I need help with Django channels and Websockets (i guess) for an application I am building. The project is online Chess game with Django as a backend and vanilla JavaScript (ajax, jQuey and some bootstrap). We are using custom chess engine written in python.  

Previously we succesfully built flask application with single view to play chess game hand-to-hand. I wanted to improve our backend and introduce game lobbies - general online. This would also be a great practice and learning. Or so I thought.
I have gone through the Django Channels docs and followed simple tutorial to create a chat application - more or less the concept is understood. 

My goal is to create a lobby like system as in other online games:
  • User has to be autorized and only authorized users can do anything
  • You can click on "New game" - it will put you in waiting or lobby room. If you match with another user who has right conditions (for now: oppotise pieces color) - you two are put in a game and game starts
  • If there are no games available after some timeout - it will through you out to main screen and ask to "Try later"
I have some ideas and questions, but I would like to hear how this idea can be coded and what would be the right plan for realisation first. Maybe my questions and ideas are completely irrelevant.

P.S.: We are using custom written chess engine in Python via OOP. It worked very poorly in Flask by just creating Game object from a class in View function. This you should not do... What would be the best practice to actually access it and when we should create it? I have seen examples with TicTacToe game and logic stored as a model, but i think it would be very heavy on database....

Looking forward for replies :) 

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca46cb38-d3a7-4d24-b5f2-b7fda612f445n%40googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFGN%3DGhNrCdxmiQqLhtOPZHsMOovntxsunuriUDezhtHRbOfxQ%40mail.gmail.com.

Django Channels with Queue (Lobby) Manager

Hello dear Community!

I need help with Django channels and Websockets (i guess) for an application I am building. The project is online Chess game with Django as a backend and vanilla JavaScript (ajax, jQuey and some bootstrap). We are using custom chess engine written in python.  

Previously we succesfully built flask application with single view to play chess game hand-to-hand. I wanted to improve our backend and introduce game lobbies - general online. This would also be a great practice and learning. Or so I thought.
I have gone through the Django Channels docs and followed simple tutorial to create a chat application - more or less the concept is understood. 

My goal is to create a lobby like system as in other online games:
  • User has to be autorized and only authorized users can do anything
  • You can click on "New game" - it will put you in waiting or lobby room. If you match with another user who has right conditions (for now: oppotise pieces color) - you two are put in a game and game starts
  • If there are no games available after some timeout - it will through you out to main screen and ask to "Try later"
I have some ideas and questions, but I would like to hear how this idea can be coded and what would be the right plan for realisation first. Maybe my questions and ideas are completely irrelevant.

P.S.: We are using custom written chess engine in Python via OOP. It worked very poorly in Flask by just creating Game object from a class in View function. This you should not do... What would be the best practice to actually access it and when we should create it? I have seen examples with TicTacToe game and logic stored as a model, but i think it would be very heavy on database....

Looking forward for replies :) 

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca46cb38-d3a7-4d24-b5f2-b7fda612f445n%40googlegroups.com.

Monday, July 10, 2023

Re: Running migrations with multiple databases

Migrations are executed according to how your db routers is setup.

See setting DATABASE_ROUTERS.

Note that normally you would be replicating secondaries, so migrations are normally not applied on all bu the primary, so this is the default.

Regards,
David

On Mon, Jul 10, 2023 at 10:26 PM Shaheed Haque <shaheedhaque@gmail.com> wrote:
Hi,

I'm on Django 4.2 atop Postgres. In my project settings.py, I have a main/default database connection, and a second set up like this:

==============
DATABASES = {
    'default': {
        ...
        'NAME': 'foo',                     # Postgres DATABASE NAME
        ...
    },
    'archive_restore': {
        ...
        'NAME': 'archive_restore',   # Postgres DATABASE NAME
        ...
    },
    # Other entries for specialised purposes such as custom Postgres Foreign Data Wrappers.
===============

As you can see, the Postgres database names are "foo" and "archive_restore" respectively. For all normal Django purposes, we want to use "default", aka "foo". The "archive_restore" connection/database is used in conjunction with a bunch of psql commands to create a subset of the main Django ORM data. Once populated via pg_restore, I need to run the DJango migrations on them for eventual use under Django. I had assumed that a command like this:

./manage.py migrate --database archive_restore

would modify archive_restore/archive_restore. However, what seems to happen is that the migrations are:
  • Actually run in default/foo (the migrations include code generated by makemigrations and custom RunPython stuff).
  • But recorded in the django_migrations table in archive_restore/archive_restore.
whereas I was expecting that they would be both run and recorded in the latter. Have I overlooked some setting/restriction, or is this a bug?

Thanks, Shaheed




--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHAc2je%2B%3D67tZBeGBMUO8Dmqmq9SaCRuopLxqrECuXb1C8YriQ%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAE5VhgXQj3yTmiqvKn3hVoBD7PT4aF58aXtN9euUs_AgEiLTvw%40mail.gmail.com.

Re: Calculations

Ah ok, looks like aggregate always returns a dictionary. This should work:

outstanding_balance = loan.amount_to_pay - loan.payments_set.aggregate(paid=Sum("amount"))['paid']

On Monday, July 10, 2023 at 11:03:06 AM UTC+1 Abdou KARAMBIZI wrote:
Hello Thomas 

I have tried but I got that error message

On Fri, Jul 7, 2023 at 5:03 PM Thomas Couch <t.c...@ucl.ac.uk> wrote:
Hi Abdou, have a look at aggregation (https://docs.djangoproject.com/en/4.2/topics/db/aggregation/)

In this case I think you'll want something like:

```
from django.db.models import Sum

# Where loan = the LoanInformation instance you're interested in
outstanding_balance = loan.amount_to_pay - loan.payments_set.aggregate(Sum("amount"))
```


On Thursday, July 6, 2023 at 5:39:50 PM UTC+1 Abdou KARAMBIZI wrote:
class LoanInformation(models.Model):
    id = models.AutoField(primary_key=True)
    customer = models.ForeignKey(Customer,on_delete=models.CASCADE)
    amount_to_pay = models.IntegerField()
 
    def __str__ (self):
        return self.id

class Payments(models.Model):
    id = models.AutoField(primary_key = True)
    loan = models.ForeignKey(LoanInformation,on_delete=models.CASCADE)
    amount = models.IntegerField()
    paidon = models.DateField(auto_now=True)

    def __str__ (self):
        return self.id



I want to display the result of  "amount_to_pay - sum of amount"

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1b059aab-1b8e-4a8e-b9e3-d7cb9d1f5673n%40googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9be67e3f-785b-4c39-ab6c-309fd33a8289n%40googlegroups.com.

Friday, July 7, 2023

Re: Calculations

Or, you can combine annotations and expressions to do something like this:

qs = LoanInformation.objects.annotate(outstanding=F("amount_to_pay") - Func(F("payments__amount"), function="SUM))
loan = qs.get(id=loan_id)
loan.outstanding

On Friday, July 7, 2023 at 4:03:09 PM UTC+1 Thomas Couch wrote:
Hi Abdou, have a look at aggregation (https://docs.djangoproject.com/en/4.2/topics/db/aggregation/)

In this case I think you'll want something like:

```
from django.db.models import Sum

# Where loan = the LoanInformation instance you're interested in
outstanding_balance = loan.amount_to_pay - loan.payments_set.aggregate(Sum("amount"))
```


On Thursday, July 6, 2023 at 5:39:50 PM UTC+1 Abdou KARAMBIZI wrote:
class LoanInformation(models.Model):
    id = models.AutoField(primary_key=True)
    customer = models.ForeignKey(Customer,on_delete=models.CASCADE)
    amount_to_pay = models.IntegerField()
 
    def __str__ (self):
        return self.id

class Payments(models.Model):
    id = models.AutoField(primary_key = True)
    loan = models.ForeignKey(LoanInformation,on_delete=models.CASCADE)
    amount = models.IntegerField()
    paidon = models.DateField(auto_now=True)

    def __str__ (self):
        return self.id



I want to display the result of  "amount_to_pay - sum of amount"

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/700326cd-ec0c-471d-9e51-8a30fb9fd64bn%40googlegroups.com.

Re: Calculations

Hi Abdou, have a look at aggregation (https://docs.djangoproject.com/en/4.2/topics/db/aggregation/)

In this case I think you'll want something like:

```
from django.db.models import Sum

# Where loan = the LoanInformation instance you're interested in
outstanding_balance = loan.amount_to_pay - loan.payments_set.aggregate(Sum("amount"))
```


On Thursday, July 6, 2023 at 5:39:50 PM UTC+1 Abdou KARAMBIZI wrote:
class LoanInformation(models.Model):
    id = models.AutoField(primary_key=True)
    customer = models.ForeignKey(Customer,on_delete=models.CASCADE)
    amount_to_pay = models.IntegerField()
 
    def __str__ (self):
        return self.id

class Payments(models.Model):
    id = models.AutoField(primary_key = True)
    loan = models.ForeignKey(LoanInformation,on_delete=models.CASCADE)
    amount = models.IntegerField()
    paidon = models.DateField(auto_now=True)

    def __str__ (self):
        return self.id



I want to display the result of  "amount_to_pay - sum of amount"

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1b059aab-1b8e-4a8e-b9e3-d7cb9d1f5673n%40googlegroups.com.

Re: Freelance Django and Python work

Hi, I am looking for opportunity in python to accelerate my career growth, please consider this 
Mobile:8299835153

On Wed, 5 Jul, 2023, 10:43 pm kumbhaj shukla, <kumbhajs0@gmail.com> wrote:

On Wed, Jul 5, 2023, 8:27 PM Dawn Wages <dawn.wages@gmail.com> wrote:
Hi Uri,

Are you still looking for a freelancer? I'm currently a Python Developer Advocate at Microsoft, but I'm looking to pick up a bit of extra freelance work. Here's my resume.
 
Best,

DW

Dawn Wages 
Web, Data & Ethical OSS Engineer
+1 215 294 0320






✊🏾 antiracist open source license and SDK: www.AtTheRoot.dev and newsletter (RSS)
   
 frequently updated calendar and occasional newsletter (RSS) about A11y, django, wagtail, tech for good


‪On Tue, Jun 13, 2023 at 7:29 AM ‫אורי‬‎ <uri@speedy.net> wrote:‬
Hi,

I'm looking for a programmer to hire as a freelancer for Django and Python work.

- Experience with Python and Django
- Experience with open source
- Committed to the Django repository on GitHub - an advantage
- Committed to other open-source projects in Python - an advantage
- Experience with Stack Overflow -  an advantage
- BSc or BA in computers or science (math, physics) -  an advantage
- Knowledge of HTML, CSS, and JavaScript - an advantage
- Can issue receipts

I need about 5 hours per month on average. Some months I might need up to 15 hours per month. Some months I might not need anything. The work is remote. My project is open source. I can give you a free license to PyCharm. My website is at https://en.speedy.net/ and https://github.com/speedy-net/speedy-net

To apply please send one email to jobs+jango-freelancer@speedy.net, with your name, your email address, where you live, your experience, how many commits you committed to Django, how many commits you committed to other open source projects, a link to your profile on LinkedIn, a link to your profile on GitHub, a link to your profile on Stack Overflow, your diploma if you have any, how much you charge per hour and in which currency (I prefer USD or Euro), and if you can issue receipts. If you don't have a profile on one of the above websites please mention this too.

Thanks,
Uri Rodberg, Speedy Net.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeHjQyFa75Mgq7nzcJ6AoX-WDeu75OOPfa2OngG2VTMaDQ%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN2_Vwu_vEztv-Wz5ihFt%2B21MzNXW%3DMfvKPFMUA5-xMFmpVA%2Bg%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPjc%3DUWO4dCZOgQgd7DV8Y1%3DcmT2RpaVuQWXn_%3DgE6cXjFiXcA%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMzbe2ku6gMFA7AR%2BgCG5%3DmGbZTM9T23z1%2BffenknJsftGAU1Q%40mail.gmail.com.