Skip to main content
se añadió 1 carácter en el cuerpo
Origen Enlace

Tengo 2 ficheros y quiero importar esta función que tengo en este fichero carga.py

class Command(BaseCommand):
   def rango_fecha((self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[date, date]:):
      print("lo que sea")

Y usarla aquí: fichero2.py

from foro.management.commands.carga import Command as FechaCommand

class Command(BaseCommand):
   def rango_fecha(self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[
    date, date]:
       return super(FechaCommand, self).date_rangerango_fecha(anio, empieza, end)

   def handle(self, *args, anio: Optional[int]=None, empieza: Optional[str]=None, end: Optional[str]=None, **options):
       fecha_fin = self.rango_fecha(anio, empieza, end) # esto da error por eso quiero usar el super

¿Cómo tendría que hacer el super correctamente?

Mensaje de error:

TypeError: super(type, obj): obj must be an instance or subtype of type

Tengo 2 ficheros y quiero importar esta función que tengo en este fichero carga.py

class Command(BaseCommand):
   def rango_fecha((self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[date, date]:):
      print("lo que sea")

Y usarla aquí: fichero2.py

from foro.management.commands.carga import Command as FechaCommand

class Command(BaseCommand):
   def rango_fecha(self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[
    date, date]:
       return super(FechaCommand, self).date_range(anio, empieza, end)

   def handle(self, *args, anio: Optional[int]=None, empieza: Optional[str]=None, end: Optional[str]=None, **options):
       fecha_fin = self.rango_fecha(anio, empieza, end) # esto da error por eso quiero usar el super

¿Cómo tendría que hacer el super?

Mensaje de error:

TypeError: super(type, obj): obj must be an instance or subtype of type

Tengo 2 ficheros y quiero importar esta función que tengo en este fichero carga.py

class Command(BaseCommand):
   def rango_fecha((self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[date, date]:):
      print("lo que sea")

Y usarla aquí: fichero2.py

from foro.management.commands.carga import Command as FechaCommand

class Command(BaseCommand):
   def rango_fecha(self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[
    date, date]:
       return super(FechaCommand, self).rango_fecha(anio, empieza, end)

   def handle(self, *args, anio: Optional[int]=None, empieza: Optional[str]=None, end: Optional[str]=None, **options):
       fecha_fin = self.rango_fecha(anio, empieza, end)

¿Cómo tendría que hacer el super correctamente?

Mensaje de error:

TypeError: super(type, obj): obj must be an instance or subtype of type

se eliminaron 2613 caracteres en el cuerpo
Origen Enlace

Tengo 2 ficheros y quiero importar unaesta función que tengo en este fichero carga.py

fichero2Y usarla aquí: fichero2.py

from foro.management.commands.carga import Command as FechaCommand

class Command(BaseCommand):
   def rango_fecha(self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[
    date, date]:
       return super(FechaCommand, self).date_range(anio, empieza, end)

   def handle(self, *args, anio: Optional[int]=None, empieza: Optional[str]=None, end: Optional[str]=None, **options):
       fecha_fin = FechaCommand()self.rango_fecha(anio, empieza, end) # esto da error por eso quiero usar el super

Entiendo que si lo cambio a super() el mensajeMensaje de error no me lo dará.:

Mensaje de errorTypeError: super(type, obj): obj must be an instance or subtype of type

File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 741, in save force_update=force_update, update_fields=update_fields) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 779, in save_base force_update, using, update_fields, File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 870, in _save_table result = self.do_insert(cls.base_manager, using, fields, update_pk, raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 908, in do_insert using=using, raw=raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\query.py", line 1186, in insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1374, in execute_sql for sql, params in self.as_sql(): File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in as_sql for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1317, in [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Usersjames\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1258, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 793, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1279, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1274, in get_prep_value return self.to_python(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1236, in to_python parsed = parse_date(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date match = date_re.match(value) TypeError: expected string or bytes-like object

Process finished with exit code 1

Tengo 2 ficheros y quiero importar una función que tengo en este fichero carga.py

fichero2.py

from foro.management.commands.carga import Command as FechaCommand

class Command(BaseCommand):
   def handle(self, *args, anio: Optional[int]=None, empieza: Optional[str]=None, end: Optional[str]=None, **options):
    fecha_fin = FechaCommand().rango_fecha(anio, empieza, end) # esto da error por eso quiero usar el super

Entiendo que si lo cambio a super() el mensaje de error no me lo dará.

Mensaje de error:

File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 741, in save force_update=force_update, update_fields=update_fields) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 779, in save_base force_update, using, update_fields, File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 870, in _save_table result = self.do_insert(cls.base_manager, using, fields, update_pk, raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 908, in do_insert using=using, raw=raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\query.py", line 1186, in insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1374, in execute_sql for sql, params in self.as_sql(): File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in as_sql for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1317, in [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Usersjames\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1258, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 793, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1279, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1274, in get_prep_value return self.to_python(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1236, in to_python parsed = parse_date(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date match = date_re.match(value) TypeError: expected string or bytes-like object

Process finished with exit code 1

Tengo 2 ficheros y quiero importar esta función que tengo en este fichero carga.py

Y usarla aquí: fichero2.py

from foro.management.commands.carga import Command as FechaCommand

class Command(BaseCommand):
   def rango_fecha(self, anio: Optional[int], empieza: Optional[str], end: Optional[str]) -> Tuple[
    date, date]:
       return super(FechaCommand, self).date_range(anio, empieza, end)

   def handle(self, *args, anio: Optional[int]=None, empieza: Optional[str]=None, end: Optional[str]=None, **options):
       fecha_fin = self.rango_fecha(anio, empieza, end) # esto da error por eso quiero usar el super

Mensaje de error:

TypeError: super(type, obj): obj must be an instance or subtype of type

Cómo ¿Cómo hacer un super de una función que está en otro fichero?

Tengo 2 ficheros y quiero importar el una función que tengo en este fichero

carga.py carga.py

Entiendo que si lo cambio a super()super() el mensaje de error no me lo dará. mensaje de error:

File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 741, in save force_update=force_update, update_fields=update_fields) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 779, in save_base force_update, using, update_fields, File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 870, in _save_table result = self.do_insert(cls.base_manager, using, fields, update_pk, raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 908, in do_insert using=using, raw=raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\query.py", line 1186, in insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1374, in execute_sql for sql, params in self.as_sql(): File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in as_sql for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1317, in [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Usersjames\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1258, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 793, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1279, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1274, in get_prep_value return self.to_python(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1236, in to_python parsed = parse_date(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date match = date_re.match(value) TypeErrorMensaje de error: expected string or bytes-like object

Process finished with exit code 1

File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 741, in save force_update=force_update, update_fields=update_fields) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 779, in save_base force_update, using, update_fields, File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 870, in _save_table result = self.do_insert(cls.base_manager, using, fields, update_pk, raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 908, in do_insert using=using, raw=raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\query.py", line 1186, in insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1374, in execute_sql for sql, params in self.as_sql(): File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in as_sql for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1317, in [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Usersjames\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1258, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 793, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1279, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1274, in get_prep_value return self.to_python(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1236, in to_python parsed = parse_date(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date match = date_re.match(value) TypeError: expected string or bytes-like object

Process finished with exit code 1

Cómo hacer un super de una función que está en otro fichero

Tengo 2 ficheros y quiero importar el una función que tengo en este fichero

carga.py

Entiendo que si lo cambio a super() el mensaje de error no me lo dará. mensaje de error:

File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 741, in save force_update=force_update, update_fields=update_fields) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 779, in save_base force_update, using, update_fields, File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 870, in _save_table result = self.do_insert(cls.base_manager, using, fields, update_pk, raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 908, in do_insert using=using, raw=raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\query.py", line 1186, in insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1374, in execute_sql for sql, params in self.as_sql(): File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in as_sql for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1317, in [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Usersjames\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1258, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 793, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1279, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1274, in get_prep_value return self.to_python(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1236, in to_python parsed = parse_date(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date match = date_re.match(value) TypeError: expected string or bytes-like object

Process finished with exit code 1

¿Cómo hacer un super de una función que está en otro fichero?

Tengo 2 ficheros y quiero importar una función que tengo en este fichero carga.py

Entiendo que si lo cambio a super() el mensaje de error no me lo dará.

Mensaje de error:

File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 741, in save force_update=force_update, update_fields=update_fields) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 779, in save_base force_update, using, update_fields, File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 870, in _save_table result = self.do_insert(cls.base_manager, using, fields, update_pk, raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\base.py", line 908, in do_insert using=using, raw=raw) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\query.py", line 1186, in insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1374, in execute_sql for sql, params in self.as_sql(): File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in as_sql for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1318, in for obj in self.query.objs File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1317, in [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Usersjames\entorno\myvenv\lib\site-packages\django\db\models\sql\compiler.py", line 1258, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 793, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1279, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1274, in get_prep_value return self.to_python(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\db\models\fields_init.py", line 1236, in to_python parsed = parse_date(value) File "C:\Users\james\entorno\myvenv\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date match = date_re.match(value) TypeError: expected string or bytes-like object

Process finished with exit code 1

se añadieron 72 caracteres en el cuerpo
Origen Enlace
Loading
Origen Enlace
Loading