You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some automation reasons, I was trying to create problems from command lines.
What I did was to invoke python manage.py create_problem ... since I accidently found this command though it seems to not appear in the docs.
Then I got an error saying TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use types.set() instead, at the line problem.types = [ProblemType.objects.get(name=options['type'])], in judge/management/commands/create_problem.py
After doing some searches online, I had a workaround that changes the code as
def handle(self, *args, **options):
problem = Problem()
problem.code = options['code']
problem.name = options['name']
problem.description = options['body']
problem.group = ProblemGroup.objects.get(name=options['group'])
#problem.types = [ProblemType.objects.get(name=options['type'])] # <---changes begin here
types = ProblemType.objects.get(name=options['type'])
problem.save()
problem.types.set([types]) # <---changes end here
problem.save()
Then the error became django.db.utils.IntegrityError: (1048, "Column 'time_limit' cannot be null") which was solved by adding a line problem.time_limit = ... After repeating this for the fields .memory_limit and .points and adding corresponding arguments to the parser, it eventually works, and the newly added problem seems good on the webpage.
While a few questions come to me:
I am not familiar with Django so I wonder if my code above is correct/safe to operate on the models. Is there a better way to do the same?
What is the standard way to add problems from command lines? python manage.py create_problem is not documented and it needs quite a few changes to be functional.
The text was updated successfully, but these errors were encountered:
I am not familiar with Django so I wonder if my code above is correct/safe to operate on the models. Is there a better way to do the same?
Your code looks fine to me. There was a change back some versions of Django that made direct assignment illegal, and it seems we forgot to update that command.
Seems like Django also got stricter around enforcing integrity and not generating defaults for time_limit and memory_limit.
What is the standard way to add problems from command lines?
python manage.py create_problem is the way to go, we just don't use it on https://dmoj.ca so it has bitrotted over time.
I think your changes seem reasonable, would you be open to creating a pull request with them?
For some automation reasons, I was trying to create problems from command lines.
What I did was to invoke
python manage.py create_problem ...
since I accidently found this command though it seems to not appear in the docs.Then I got an error saying
TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use types.set() instead
, at the lineproblem.types = [ProblemType.objects.get(name=options['type'])]
, injudge/management/commands/create_problem.py
After doing some searches online, I had a workaround that changes the code as
Then the error became
django.db.utils.IntegrityError: (1048, "Column 'time_limit' cannot be null")
which was solved by adding a lineproblem.time_limit = ...
After repeating this for the fields.memory_limit
and.points
and adding corresponding arguments to the parser, it eventually works, and the newly added problem seems good on the webpage.While a few questions come to me:
python manage.py create_problem
is not documented and it needs quite a few changes to be functional.The text was updated successfully, but these errors were encountered: